Reputation: 37
I am pretty new to Meteor and I'm just toying around to explore it at the moment. I've got stuck with an issue trying to get and set a value in the mongo database, named Persons. The MongoDB is named Persons and I've inserted two objects: {name: "abcdef", coming: "false"}
If the user changes the state of a checkbox, that's attached to a name, a function is called that should find the value of the boolean coming. What I think I got right so far, is that I can set the value like this?
var id = this._id;
Persons.update({_id: id}, {$set: {coming: true}});
But how can i get the value and make comparisons with it?
Upvotes: 0
Views: 223
Reputation: 21364
In meteor you use .find(selector).fetch()
or .findOne(selector)
on collections to get objects, where selector
is a usual mongodb selector or just an id (string). After that you can pick out any fields using the usual .
syntax of javascript.
Example:
var obj = Persons.findOne(id);
if (obj) { // the given id was found
console.log(obj.coming);
}
Upvotes: 0