[SOLVED] - Insert or update bulk records

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

Use Collection.rawCollection() e.g. Activities.rawCollection().bulkWrite()

Note that this action is async

So I should not worry about the reactivity of records in Meteor subscriptions?

It should reflect on mongodb oplog and therefore to meteor’s default reactivity

it works in default meteor. with oplog, subscribers will be notified immediatly. Without oplog, the server polls the db every 5 seconds for changes on that, which also works.

Be careful that this does NOT work with redis-oplog. I do not recommend to use redis-oplog in general, because it has many pitfalls like this (only use it if you know exactly how it needs to be used)

1 Like