Mongoose select result based on value of items in database array Mongoose select result based on value of items in database array mongoose mongoose

Mongoose select result based on value of items in database array


Model.find({$or :[{"price.1": {$exists: false}}, {"price.1": {$gt : 10}}]}) //get all documents where either second element of the price array doesn't exist OR if it does it's greater than 10    .sort("price.1") // asc. Docs without second element will come first. Use -price for desc    .exec(function(err, res){        if(err){            console.log(err)        }        else{            console.log(res)        }    });