MongoDB provides the following methods for inserting documents into a collection:MongoDB提供了以下将文档插入集合的方法:
db.collection.insertOne() |
|
db.collection.insertMany() |
db.collection.insertMany() |
db.collection.insert() |
db.collection.insert() |
The following methods can also add new documents to a collection:以下方法还可以向集合添加新文档:
db.collection.update()upsert: true option.upsert: true选项配合使用时db.collection.updateOne()upsert: true option.upsert: true选项配合使用时db.collection.updateMany()upsert: true option.upsert: true选项配合使用时db.collection.findAndModify()upsert: true option.upsert: true选项配合使用时db.collection.findOneAndUpdate()upsert: true option.upsert: true选项配合使用时db.collection.findOneAndReplace()upsert: true option.upsert: true选项配合使用时db.collection.save().db.collection.bulkWrite().See the individual reference pages for the methods for more information and examples.有关更多信息和示例,请参阅各个参考页中的方法。