About the value passed by the $and operator of mongoDB

db.inventory.find( { $and: [ { price: { $ne: 1.99 } }, { price: {$exists: true } } ] } )

this query selects all documents in the collection inventory, provided that price is not equal to 1.99 and the price field exists. My problem is that I now need to set {$ne: 1.99} after price as a variable instead of writing it out directly. But I found that if:

var obj = {},
db.inventory.find( { $and: [ { price: obj }, { price: { $exists: true } }] } )
The

query statement is invalid. I would like to ask the condition in the query statement must be written directly, can not be put into the variable? Is there any solution?

Mar.09,2021

has solved the problem and should be queried directly using the chained operation of mongoose

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea96c6-1f54.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea96c6-1f54.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?