# mongodb增删改查之增

1,816次阅读

 db.collection.insert() Creates a new document in a collection. db.collection.insertOne() Inserts a new document in a collection. db.collection.insertMany() Inserts several new document in a collection.

insertOne 和 insertMany()分别是插入一个和多个

var ss=db.test.insert({"bar":"test"})
ss

WriteResult({ "nInserted" : 1 })

var ss=db.test.insertOne({"bar":"test"})
ss
{
"acknowledged" : true,
"insertedId" : ObjectId("5afd254e2c63ae1a943bdb24")
}

The insert() method is deprecated in major driver so you should use the the .insertOne() method whenever you want to insert a single document into your collection and the .insertMany when you want to insert multiple documents into your collection.

### insertMany

db.test.insertMany([{"a":"b"},{"c":"d"}])