Document Database Service

Common Operations

2025-07-28 08:40:43

CRUD Actions

In DDS, the following are some commonly used CRUD (create, read, update, delete) operations and corresponding examples:

  • Create document (Insert):

    • Insert a single document:

  db.collection.insertOne({ name: "John", age: 25, city: "New York" });
    • Insert multiple documents:

  db.collection.insertMany([
    { name: "Alice", age: 30, city: "London" },
    { name: "Bob", age: 35, city: "Paris" }
  ]);
  • Read document (Read):

    • Query all documents in the collection:

  db.collection.find();

    • Query and return the first matching document:

    db.collection.findOne({ name: "John" });
    • Use query operator for advanced query:

    db.collection.find({ age: { $gt: 25 } });
  • Update document (Update):

    • Update a single document:

    db.collection.updateOne({ name: "John" }, { $set: { age: 26 } });
    • Update multiple documents:

    db.collection.updateMany({ city: "London" }, { $set: { age: 31 } });
  • Delete document (Delete):

    • Delete a single document:

    db.collection.deleteOne({ name: "John" });
    • Delete multiple documents:

    db.collection.deleteMany({ city: "London" });

Here are some examples of commonly used CRUD operations.


JqtRNFIJouHq