Home > Mobile >  Insert or update bulk records
Insert or update bulk records

Time:09-05

How can I update or insert bulk operations in Meteor Mongodb?

Here is my simple script:

var obj = [];
for(var i = 0; i < 100000; i  ){
    obj.push({title: i, inTime: new Date(), outTime: new Date})
}

Activities.bulkWrite([
    { 
        insertMany: obj 
    }
])

Why I am getting this error:

Exception while invoking method TypeError: Activities.bulkWrite is not a function

CodePudding user response:

Not sure of what is Activities is referred to here.
If Activities is the schema or collection object, then just use as Activities.insertMany function to insert all the records to your database collection.

Hope this helps!!!

CodePudding user response:

Meteor Collection object doesn't have the bulkWrite function. Remember, Meteor uses a lib to provide MongoDB function. To access the native functions of MongoDB in a collection, you need to use rawCollection. See here.

  • Related