5.MongoDB CRUD Operations-官方文档摘录

本文介绍了MongoDB中创建(create)、读取(read)、更新(update)和删除(delete)等基本操作,包括3.2版本中新引入的方法如insertOne、insertMany等,并详细解释了这些方法的具体使用场景。

总结

1. CRUD:createreadupdate, and delete DOCUMENT

2.在3.2版本的插入方式

db.collection.insertOne()
db.collection.insertMany()
 
  

db.users.insertOne(
{
name:"sue",
age:26,
status:"pending"

}
)

  

3 Read 操作

db.users.find(
{
age:{$gt:18},
name:1,address:1
}
)

4 Update操作

db.collection.updateOne()
db.collection.updatMany()
db.collection.replaceOne()

db.users.find(
{
age:{$gt:18},
name:1,address:1
}
)




 

5 Delete操作

db.users.deleteOne()
db.users.deleteMany()

 

CRUD operations createreadupdate, and 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:

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

The components of a MongoDB insertOne operations.

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.

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:

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.

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:

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.

The components of a MongoDB deleteMany operation.

For examples, see Delete Documents.

Bulk Write

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

 

转载于:https://www.cnblogs.com/olinux/p/7232476.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值