Using mongoJS https://github.com/mafintosh/mongojs
Finds everything
db.users.find({}, function(err,users){
if (err) throw err;
console.log(users);
})
Returns the user. looks great
[{ _id: 53f2faa6aed1689e84982b8b,
facebook: {
email: 'myname@gmail.com',
name: 'Juan Atkins',
id: '764969936' },
__v: 0
}]
When I try to find that user by his id: fail
db.users.findOne({
_id: '53f2faa6aed1689e84982b8b'
}, function(err, user) {
if (err) throw err;
console.log(user);
});
returns []
I know there is data in the DB. I've tried searching by a different key (like name). Why can't it find the data?
you have to use ObjectId: http://mongodb.github.io/node-mongodb-native/api-bson-generated/objectid.html
db.users.findOne({
_id: new ObjectID('53f2faa6aed1689e84982b8b')
}, function(err, user) {
if (err) throw err;
console.log(user);
});