On this page
Insert Methods
MongoDB 提供了以下用于将documents插入到集合中的方法:
db.collection.insertOne() | 将单个文档插入集合中。 |
db.collection.insertMany() | db.collection.insertMany()将* multiple * documents插入集合中。 |
db.collection.insert() | 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
选项一起使用时。
有关更多方法和示例,请参见各个方法的参考页。