Nyxynyx
Nyxynyx

Reputation: 63687

MeteorJS error "Invalid modifier. Modifier must be an object"

When the if statements containing UserSession.insert is removed, everything works fine. But when its icluded, we get te error about an invalid modifier.

What went wrong? Thank you!

server/helpers/b.s

Meteor.startup(function(){

    // Initialize
    var SUPERPACK = Meteor.require('superpack');
    var superpack = new SUPERPACK('a', 'b');


    // Get Account Info
    try {
        superpack.getInfoSync = Meteor._wrapAsync(superpack.getInfo.bind(superpack));
        var data = superpack.getInfoSync();

        // THIS PART WHEN REMOVED, REMOVES THE ERROR *********
        // Update if record exist, create if not
        if (UserSession.find().count() == 0) {

            UserSession.insert({ 'userId': 1, 'account': data});

        } else {

            UserSession.update({ 'userId': 1, 'account': data});

        }

        console.log(data);

    } catch(error) {
        console.log(error);
    }

});

Error:

superpack.getInfoSync(): Error: Invalid modifier. Modifier must be an object.

Upvotes: 0

Views: 2084

Answers (1)

Anto Jurković
Anto Jurković

Reputation: 11258

It seems that there are two errors:

The first one is with if statement:

if (UserSession.find().count() > 0) {

should be changed to

if (UserSession.find().count() == 0) {

The second one: There is missing proper modifier for update()

UserSession.update({ 'userId': 1, 'account': data});

From documentation:

collection.update(selector, modifier, [options], [callback])

selector and modifier has to be provided.

Upvotes: 2

Related Questions