LearnBoost/mongoose — Issue #559: using findOne() with an undefined value returns the first document and not an error
Author: mansona
Created: 2011-10-10 10:20:18+00:00
State: open

The code I'm using is:

LoginModel.findOne({'fbLogin.userID' : req.body.id}, function(err, doc){
//Here err is null and doc is the first (and only) object in the collection used by the LoginModel.
});

Please note that req.body.id is undefined.

I would expect this to thow an error. I tried the same thing using the mongo client and I get the following error:

> db.logins.find({'fbLogin.userId': undefined})
error: { "$err" : "can't have undefined in a query expression", "code" : 13629 }

This seems like an inconsistency between mongo and mongoose.