MongoDB CRUD OperationsMongoDB CRUD操作
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提供了以下方法将文档插入到集合中:
db.collection.insertOne()
New in version 3.2db.collection.insertMany()
New in version 3.2
In MongoDB, insert operations target a single collection. 在MongoDB中,插入操作针对单个集合。All write operations in MongoDB are atomic on the level of a single document.MongoDB中的所有写操作都是单个文档级别上的原子操作。
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.您可以指定用于标识要返回的文档的查询筛选器或条件。
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提供了以下方法来更新集合的文档:
db.collection.updateOne()
New in version 3.2db.collection.updateMany()
New in version 3.2db.collection.replaceOne()
New in version 3.2
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.这些筛选器使用与读取操作相同的语法。
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提供了以下方法来删除集合中的文档:
db.collection.deleteOne()
New in version 3.2db.collection.deleteMany()
New in version 3.2
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.您可以指定用于标识要删除的文档的条件或筛选器。这些筛选器使用与读取操作相同的语法。
For examples, see Delete Documents.有关示例,请参阅删除文档。
Bulk Write大容量写入
MongoDB provides the ability to perform write operations in bulk. For details, see Bulk Write Operations.MongoDB提供了批量执行写操作的能力。有关详细信息,请参阅大容量写入操作。