Inserting multiple documents into mongodb using one call in Meteor

Viewed 3600

In the mongo shell, it is possible to insert an array of documents with one call. In a Meteor project, I have tried using

MyCollection = new Mongo.Collection("my_collection")
documentArray = [{"one": 1}, {"two": 2}]
MyCollection.insert(documentArray)

However, when I check my_collection from the mongo shell, it shows that only one document has been inserted, and that document contains the entire array as if it had been a map:

db.my_collection.find({})
{ "_id" : "KPsbjZt5ALZam4MTd", "0" : { "one" : 1 }, "1" : { "two" : 2} }

Is there a Meteor call that I can use to add a series of documents all at once, or must use a technique such as the one described here?

I imagine that inserting multiple documents in a single call would optimize performance on the client side, where the new documents would become available all at once.

2 Answers
Related