I'm using a Meteor.Method and trying to insert multiple documents as show in online documents
I'm using this pattern to produce an array of documents to insert.
var arr = [];
for (i=0;i<10;i++){
doc = {}
doc["A"] = i;
doc["B"] = i*18;
arr.push(doc)
}
bulks.insert(arr)
instead of inserting multiple documents, it embeds each document in my arr
into a single new document:
{
"_id" : "YqfTbSmrGEcTAhFhj",
"0" : {"A" : 0, "B" : 0 },
"1" : {"A" : 1,"B" : 18},
"2" : {"A" : 2,"B" : 36},
"3" : {"A" : 3,"B" : 54},
{...},
"9" : {"A" : 9,"B" : 162}
}
How can I construct the array to ensure that the documents are inserted individualy?
e.g.
{ "_id" : "YqfTbSmrGEcTAhFhj", "A" : 0, "B" : 0 }
{ "_id" : "mrGEcTAhFhjYqfTbS", "A" : 1, "B" : 18 }
{ "_id" : "hjYqfTmrGEcTAhFbS", "A" : 2, "B" : 36 }
{...}
{ "_id" : "hjYqfTmrGEcTAhFbS", "A" : 9, "B" : 182}
[added info] I have been successfully able to do this in the shell, but not in Meteor - so it is possible a limitation of the driver.
Is it possible to do this with Meteor?