MongoDB - MongoDB CRUD Operations
2016-12-01 03:05
337 查看
CRUD operations create, read, update, and delete documents.
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 are atomic on the level of a single document.
![](https://images2015.cnblogs.com/blog/714359/201612/714359-20161201025755771-1121198257.png)
For examples, see Insert Documents.
db.collection.find()
You can specify query filters or criteria that identify the documents to return.
![](https://images2015.cnblogs.com/blog/714359/201612/714359-20161201025956537-1905813748.png)
For examples, see Query Documents.
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 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.
![](https://images2015.cnblogs.com/blog/714359/201612/714359-20161201030217802-1630187290.png)
For examples, see Update Documents.
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 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.
![](https://images2015.cnblogs.com/blog/714359/201612/714359-20161201030309724-375564519.png)
For examples, see Delete Documents.
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:
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 are atomic on the level of a single document.
![](https://images2015.cnblogs.com/blog/714359/201612/714359-20161201025755771-1121198257.png)
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 that identify the documents to return.
![](https://images2015.cnblogs.com/blog/714359/201612/714359-20161201025956537-1905813748.png)
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 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.
![](https://images2015.cnblogs.com/blog/714359/201612/714359-20161201030217802-1630187290.png)
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 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.
![](https://images2015.cnblogs.com/blog/714359/201612/714359-20161201030309724-375564519.png)
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, Insert Documents
- MongoDB - MongoDB CRUD Operations, Query Documents
- MongoDB - MongoDB CRUD Operations, Delete Documents
- MongoDB—— 读操作 Core MongoDB Operations (CRUD)
- MongoDB - MongoDB CRUD Operations, Query Documents, Project Fields to Return from Query
- MongoDB - MongoDB CRUD Operations, Update Documents
- MongoDB - MongoDB CRUD Operations, Bulk Write Operations
- MongoDB—— 写操作 Core MongoDB Operations (CRUD)
- MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields
- MongoDB - MongoDB CRUD Operations, Query Documents, Iterate a Cursor in the mongo Shell
- MongoDB—— 读操作 Core MongoDB Operations (CRUD)
- MongoDB Manual 3.6 The mongo Shell CRUD operations create, read, update, and delete documents(增删改查)
- MongoDB—— 写操作 Core MongoDB Operations (CRUD)
- MongoDB—— 写操作 Core MongoDB Operations (CRUD)
- MongoDB—— 写操作 Core MongoDB Operations (CRUD)
- MongoDB—— 读操作 Core MongoDB Operations (CRUD)
- MongoDB—— 读操作 Core MongoDB Operations (CRUD)
- MongoDB学习 (四):创建、读取、更新、删除(CRUD)快速入门
- mongoDB第二讲:CRUD_part1
- Java调用MongoDB CRUD