Mongo Aggregation for inventory stock data
Try this:
db.collection.find({"availabe_in.stock" : {$lt : 10}})
or using aggregation pipeline:
db.collection.aggregate([{ $match :{ "availabe_in.stock" : {$lt : 10} }}])
Note : 0 is also less than 10, so you dont need any special or
query to add equals to 0
condition
If you want to get only those elements of available_in
array which match, then you can use below aggregation pipeline:
db.collection.aggregate([{ $unwind : "$available_in"},{ $match : { "available_in.stock" : { $lt : 10 } }},{ $group : { _id : "$_id", name : {$first : "$name"}, available_in : {$push : "$available_in"} }}])