MongoDB入门-插入文档

2020-10-29  本文已影响0人  似朝朝我心

我这里使用的数据库可视化工具是RoBo 3T社区版作为展示。

db.collection.insert()方法,向集合内传入一个或多个文档,一个文档的时候传的是对象,多个文档传的是数组。


效果图 :


db.collection.insertOne()方法,插入一个文档对象。
db.collection.insertMany()方法,插入多个文档对象。

实际上,db.collection.insertOne()方法和db.collection.insertMany()方法都是对db.collection.insert()方法的拆分

db.collection.insertOne()方法和db.collection.insertMany()方法,语义上更加清晰,会告诉我们传几个文档对象,而db.collection.insert()方法则不明确,可以是一个文档对象,也可以是多个,总的来说,这三个方法本质上没多大区别。

上一篇下一篇

猜你喜欢

热点阅读