I would like to write the following query in Mongo:
Get all rows where field
equals var1
but/and not var2
I have this:
db["mydb"].find(
{"field": var1},
{"field": {
"$ne": var2}
}
)
But it yields the error that $ne
is an "unsupported projection option."
You can use the $and
operator to combine requirements like this:
db["mydb"].find(
{"$and": [
{"field": var1},
{"field": {
"$ne": var2
}}
]}
)
Apart from the usage of $and
, you can also fix it by using {}
to combine the filters.
db["mydb"].find({
"field": var1,
"field": {"$ne": var2}
})
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