MongoDB 增删改查 CRUD 操作

 

1.添加

创建或插入操作,将新文档添加到集合中。如果集合当前不存在,插入操作将创建集合。

提供了插入文档到一个集合中有以下方法

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 are atomic on the level of a single document.

image

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:

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

image

For examples, see:

Update Operations

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

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

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

image

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:

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

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

image

For examples, see Delete Documents.

Bulk Write

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

posted @ 2017-03-30 14:18  金泽夕  阅读(197)  评论(0编辑  收藏  举报