2015-04-16 16 views
3

密鑰is_agent的值爲TRUE或空白。我有以下查詢:mongodb查詢布爾值的語法是什麼?

db.users.find({ $not: {is_agent:TRUE} }, {email:1}) 

我得到以下錯誤:

ReferenceError: TRUE is not defined 

當我用"TRUE"我得到了以下錯誤:

"$err" : "Can't canonicalize query: BadValue unknown top level operator: $not", 
"code" : 17287 

什麼是正確的語法?

回答

4

$eq Matches values that are equal to a specified value.

$ne Matches all values that are not equal to a specified value.

Documentation on mongodb operators

實施例:

db.users.find({is_agent: {$ne: true}}) 

db.users.find({is_agent: {$eq: true}})