Home > Software engineering >  How to solve "compare to undefined" problem?
How to solve "compare to undefined" problem?

Time:03-24

I have collections users and orders and i do:

user=db.users.find({username:"tom"})
db.orders.find({user_id:user['_id']})

And i get this error:

Error: error: {
        "ok" : 0,
        "errmsg" : "cannot compare to undefined",
        "code" : 2,
        "codeName" : "BadValue"
}

CodePudding user response:

find returns a cursor, maybe try

user=db.users.findOne({username:"tom"}); 
if (user != null) 
   db.orders.find({user_id:user['_id']})
  • Related