Reputation: 4631
I defined 2 variables in the interactive shell of MongoDB:
a = {"letter": "a"}
b = {"letter": "b"}
Now I'd like to add them to a collection newColl
in the database stackoverflow
:
use stackoverflow
db.newColl.insert(a)
db.newColl.insert(b)
I was wondering, if it is possible to insert both documents in one go, for example like:
// Not working!
db.newColl.insert(a, b)
Upvotes: 1
Views: 126
Reputation: 197
Just use arrays:
db.collection.isert([doc1:adsadad, doc2:asdad, etc, etc])
http://docs.mongodb.org/manual/reference/method/db.collection.insert/
Upvotes: 1
Reputation: 311835
If you put both docs into an array it will work:
db.newColl.insert([a, b])
Upvotes: 2