On this page本页内容
CRUD operations create, read, update, and delete documents.CRUD操作创建、读取、更新和删除文档。
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()
db.collection.insertMany()
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 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 modify existing documents in a collection.更新操作修改集合中的现有文档。MongoDB provides the following methods to update documents of a collection:MongoDB提供以下方法来更新集合的文档:
db.collection.updateOne()
db.collection.updateMany()
db.collection.replaceOne()
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 remove documents from a collection.删除操作从集合中删除文档。MongoDB provides the following methods to delete documents of a collection:MongoDB提供了以下方法来删除集合的文档:
db.collection.deleteOne()
db.collection.deleteMany()
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.有关示例,请参见删除文档。
MongoDB provides the ability to perform write operations in bulk.MongoDB提供批量执行写操作的能力。For details, see Bulk Write Operations.有关详细信息,请参阅批量写入操作。