Skip to content Skip to sidebar Skip to footer

How To Update A Mongo.db Collection In Meteor.js?

I have a collection that I need to update when the user presses a button. I just need to change one variable to another. In the console, this line of code works: db.users.update(

Solution 1:

Found the problem.

Since I defined my database in my lib.js file

users = new Meteor.collection("users");

I don't need to put a db in front of the db.users.update({_id : "Jack"},{...}). I also need to find the document using the given mongo _id, not the identifier "username".

so the appropriate code would be

users.update({_id : "Jack"},{$set:{age : 13, username : "Jack"}});

Solution 2:

This might not be the problem as you've stated you do not get a error message but to be sure: have you already allowed the user to update documents in the user collection?

Something like:

(in collections/permissions.js)

user.allow({
update: function (userId) {
    // the user must be logged in to allow updates
    return (userId != null);
}

})


Post a Comment for "How To Update A Mongo.db Collection In Meteor.js?"