mongoDB Shell Returning products who are 5% far from the minimum stock

35 views Asked by At

I try to Return all the products who are 5% far from the minimum stock in mongoDB

in the mongoDB product collation I have :

_id, name, img, price, inStock

_id: ObjectId("6523432dfsad123323g6h")
name: air force
img: "some URL"
price: 250 
inStock: 60

minimum stock is 0

And if that helps, let's say the maximum stock is 50

Imagine I have more such products like this And I want to return only the products that are going to run out

I tried a lot of ways but I can not if anyone can help me I would be very happy I try to do this only in mongodb shell. ty

1

There are 1 answers

0
rickhg12hs On

Here's one way to find docs where "inStock" is "$lte" to 11.

db.collection.find({
  "inStock": {
    "$lte": 11
  }
})

Try it on mongoplayground.net.