简体   繁体   中英

How to use a query object in a Mongoose query?

I have a query object like this:

{$and: [length: {$gt: 10}, sentiment {$gt: 0.23}]}

Call this const q.

So I want to find all documents in a Mongo collection that fits these parameters (where the doc's "length" is greater than 10 and it's "sentiment" is greater than .23). What would the Mongoose query I write look like?

Query in mongoose will be

await CollectionName.find({
    {$and: [{"length": {$gt: 10}}, {"sentiment": {$gt: 0.23}}]}
})

You can try :

Collection.find({
    $and: [{"length": {$gt: 10}}, {"sentiment": {$gt: 0.23}}]
    }, function (err, results) {    
    ...
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM