MongoDB CRUD Operations操作

On this page本页内容

CRUD operations create, read, update, and delete documents.CRUD操作创建读取更新删除文档

Create Operations创建操作

Create or insert operations add new documents to a collection.创建或插入操作将新文档添加到集合中。If the collection does not currently exist, insert operations will create the collection.如果集合当前不存在,插入操作将创建集合。

MongoDB provides the following methods to insert documents into a collection:MongoDB提供了以下方法将文档插入到集合中:

In MongoDB, insert operations target a single collection.在MongoDB中,插入操作针对单个集合All write operations in MongoDB are atomic on the level of a single document.MongoDB中的所有写操作都是单个文档级别上的原子操作。

The components of a MongoDB insertOne operations.

For examples, see Insert Documents.有关示例,请参见插入文档

Read Operations读取操作

Read operations retrieve documents from a collection; i.e. query a collection for documents.读取操作从集合中检索文档;即查询集合中的文档。MongoDB provides the following methods to read documents from a collection:MongoDB提供以下方法从集合中读取文档:

You can specify query filters or criteria that identify the documents to return.可以指定用于标识要返回的文档的查询筛选器或条件

The components of a MongoDB find operation.

For examples, see:有关示例,请参见:

Update Operations更新操作

Update operations modify existing documents in a collection.更新操作修改集合中的现有文档MongoDB provides the following methods to update documents of a collection:MongoDB提供以下方法来更新集合的文档:

In MongoDB, update operations target a single collection.在MongoDB中,更新操作针对单个集合。All write operations in MongoDB are atomic on the level of a single document.MongoDB中的所有写操作都是单个文档级别上的原子操作。

You can specify criteria, or filters, that identify the documents to update.可以指定用于标识要更新的文档的条件或筛选器。These filters use the same syntax as read operations.这些筛选器使用与读取操作相同的语法。

The components of a MongoDB updateMany operation.

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:MongoDB提供了以下方法来删除集合的文档:

In MongoDB, delete operations target a single collection.在MongoDB中,删除操作针对单个集合All write operations in MongoDB are atomic on the level of a single document.MongoDB中的所有写操作都是单个文档级别上的原子操作。

You can specify criteria, or filters, that identify the documents to remove.可以指定用于标识要删除的文档的条件或筛选器。These filters use the same syntax as read operations.这些筛选器使用与读取操作相同的语法。

The components of a MongoDB deleteMany operation.

For examples, see Delete Documents.有关示例,请参见删除文档

Bulk Write批量写入

MongoDB provides the ability to perform write operations in bulk.MongoDB提供批量执行写操作的能力。For details, see Bulk Write Operations.有关详细信息,请参阅批量写入操作。