Mongodb-mongodb CRUD Operations

Source: Internet
Author: User

CRUD operations Create, read, update, and delete documents.

Create Operations

Create or Insert operations Add new documents to a collection. If The collection does not currently exist, insert operations would create the collection.

MongoDB provides the following methods to insert documents into a collection:

    • Db.collection.insert ()
    • Db.collection.insertOne () New in version 3.2
    • Db.collection.insertMany () New in version 3.2

In MongoDB, insert operations target a single collection. All write operations in MongoDB is atomic on the level of a single document.

For examples, see Insert Documents.

Read Operations

Read operations retrieves documents from a collection; i.e. queries a collection for documents. MongoDB provides the following methods to read documents from a collection:

    • Db.collection.find ()

You can specify query filters or criteria for this identify the documents to return.

For examples, see Query Documents.

Update Operations

Update Operations Modify existing documents in a collection. MongoDB provides the following methods to update documents of a collection:

    • Db.collection.update ()
    • Db.collection.updateOne () New in version 3.2
    • Db.collection.updateMany () New in version 3.2
    • Db.collection.replaceOne () New in version 3.2

In MongoDB, update operations target a single collection. All write operations in MongoDB is atomic on the level of a single document.

You can specify criteria, or filters, which identify the documents to update. These filters use the same syntax as read operations.

For examples, see Update Documents.

Delete Operations

Delete operations Remove documents from a collection. MongoDB provides the following methods to delete documents of a collection:

    • Db.collection.remove ()
    • Db.collection.deleteOne () New in version 3.2
    • Db.collection.deleteMany () New in version 3.2

In MongoDB, delete operations target a single collection. All write operations in MongoDB is atomic on the level of a single document.

You can specify criteria, or filters, which identify the documents to remove. These filters use the same syntax as read operations.

For examples, see Delete Documents.

Bulk Write

MongoDB provides the ability to perform write operations in bulk. For details, see Bulk Write Operations.

Mongodb-mongodb CRUD Operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.