参考 > MongoDB CRUD操作 > 插入文件 > 插入方法
MongoDB提供了以下将文档插入到集合中的方法:
db.collection.insertOne() |
将单个文档插入集合中。 |
db.collection.insertMany() |
db.collection.insertMany()将多个
文档插入到集合中。 |
db.collection.insert() |
db.collection.insert() 将一个或多个文档插入到集合中。 |
以下方法还可以将新文档添加到集合中:
db.collection.update()与该
选项一起使用时。upsert: truedb.collection.updateOne()与该选项一起使用时。upsert:
truedb.collection.updateMany()与该选项一起使用时。upsert:
truedb.collection.findAndModify()与该选项一起使用时。upsert:
truedb.collection.findOneAndUpdate()与该选项一起使用时
。upsert: truedb.collection.findOneAndReplace()与该选项一起使用时
。upsert: truedb.collection.save()。db.collection.bulkWrite()。有关更多方法和示例,请参见各个方法的参考页。