进入MongoDB中文手册(4.2版本)目录
MongoDB提供了以下将文档插入到集合中的方法:
方法 | 说明 |
---|---|
db.collection.insertOne() | 将单个文档插入集合中 |
db.collection.insertMany() | 将多个 文档插入集合中 |
db.collection.insert() | 将一个或多个文档插入到集合中 |
其他插入方法
以下方法也可以将新文档添加到集合中:
方法 | 说明 |
---|---|
db.collection.update() | 与upsert: true选项一起使用时 |
db.collection.updateOne() | 与upsert: true选项一起使用时 |
db.collection.updateMany() | 与upsert: true选项一起使用时 |
db.collection.findAndModify() | 与upsert: true选项一起使用时 |
db.collection.findOneAndUpdate() | 与upsert: true选项一起使用时 |
db.collection.findOneAndReplace() | 与upsert: true选项一起使用时 |
db.collection.save() | |
db.collection.bulkWrite() |