MongoDB provides the following methods for inserting documents into a collection:MongoDB提供了以下将文档插入集合的方法:
db.collection.insertOne() | |
db.collection.insertMany() |
If you use MongoDB Atlas, the fully managed service for MongoDB deployments in the cloud, you can use these methods to insert documents after you connect to your cluster. To learn more, see the following resources in the MongoDB Atlas documentation:如果你使用MongoDB Atlas,这是云中MongoDB部署的完全托管服务,你可以在连接到集群后使用这些方法插入文档。要了解更多信息,请参阅MongoDB Atlas文档中的以下资源:
Additional Methods for Inserts插入的其他方法
The following methods can also add new documents to a collection, including collections hosted in MongoDB Atlas:以下方法还可以将新文档添加到集合中,包括MongoDB Atlas中托管的集合:
db.collection.updateOne()when used with the当与upsert: trueoption.upsert: true选项一起使用时。db.collection.updateMany()when used with the当与upsert: trueoption.upsert: true选项一起使用时。db.collection.findAndModify()when used with the当与upsert: trueoption.upsert: true选项一起使用时。db.collection.findOneAndUpdate()when used with the当与upsert: trueoption.upsert: true选项一起使用时。db.collection.findOneAndReplace()when used with the当与upsert: trueoption.upsert: true选项一起使用时。db.collection.bulkWrite().
See the individual reference pages for the methods for more information and examples.有关更多信息和示例的方法,请参阅各个参考页。