I am trying to do a massive insertion from the MongoDB console of an array into a collection.
I would like to do something similar to this.
obj1 = {_id: ObjectId (), blabla: 1};
obj2 = {_id: ObjectId (), blabla: 2};
objs = [obj1, obj2];
db.test.insert (OBJS);
db.test.find ()
> {"_id": ObjectId ("xxxx"), "blabla": 1}> {"_id": ObjectId ("xxxx"), "blabla": 2}
But instead of inserting two objects into the collection, it saves a single list with two objects.
db.test.find ()
> {"_id": ObjectId ("xxx"), "0": {"_ id": ObjectId ("xxxx"), "blabla": 1}, "1": {"_ id": ObjectId (" xxxx ")," blabla ": 2}}
This functionality appears on other drivers (for example, pymongo ), but I can not find a way to do this from the mongodb console, in the JavaScript code.
source share