I am trying to find an object by _id with Meteor.
Here is what I have tried:
Meteor.publish("gifts", function(gid) {
console.log("Looking for "+ gid);
var gifts = Gifts.find({_id: gid}).fetch();
console.log("Result: " + gifts);
return gifts;
});
This is the output:
Looking for f1790caa-7a10-4af5-a01c-e80bb2c2fd55 Result:
If I take out the query:
Meteor.publish("gifts", function(gid) {
console.log("Looking for "+ gid);
var gifts = Gifts.find().fetch()[1];
console.log("Result:" + gifts._id);
return gifts;
});
The object is in the array, and the _id is the same as above.
Looking for f1790caa-7a10-4af5-a01c-e80bb2c2fd55 Result: f1790caa-7a10-4af5-a01c-e80bb2c2fd55
Also, if I execute the find in a mongo console, I find the object:
> db.gifts.find({_id: 'f1790caa-7a10-4af5-a01c-e80bb2c2fd55'});
{ "name" : "A new gift", "_id" : "f1790caa-7a10-4af5-a01c-e80bb2c2fd55" }
What am I doing wrong?