插入方法
MongoDB 提供了以下将文档插入集合的方法:
其他插入方法
以下方法还可以将新文档添加到集合中:
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
选项一起使用时。
有关更多信息和示例,请参阅这些方法的各个参考页。