Skip to content

using findOne() with an undefined value returns the first document and not an error #559

@mansona

Description

@mansona

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions