The values for the key is_agent
is TRUE or blank.
I have the following query:
db.users.find( { $not: {is_agent:TRUE} }, {email:1} )
I get the following error:
ReferenceError: TRUE is not defined
When I used "TRUE"
I got the following error:
"$err" : "Can't canonicalize query: BadValue unknown top level operator: $not",
"code" : 17287
What is the correct syntax?
Boolean is a native field type in BSON (MongoDB's server-side storage format, aka "Binary JSON"). Booleans use less storage than an integer or string and avoid any unexpected side effects of comparison.
I know there are three ways of storing the boolean data in mongodb: 0 or 1 as a String. 0 or 1 as a Number. True or False as a Boolean.
String in MongoDB must be UTF-8 valid. Integer − This type is used to store a numerical value. Integer can be 32 bit or 64 bit depending upon your server. Boolean − This type is used to store a boolean (true/ false) value.
MongoDB queries are based on JavaScript. The language is reasonably easy to learn and many tools are available to query MongoDB data using SQL syntax.
$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
Example:
db.users.find({is_agent: {$ne: true}})
or
db.users.find({is_agent: {$eq: true}})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With