0

I am trying to query a mongodb list in a single document. As shown below, I would like to match the code and get wheels value. if code = car then query should return wheels and allowed value for that list element. Below is a list from single document.

"vehicles" : [ 
        {
            "code" : "car",
        "wheels":4,
            "allowed": True
        }, 
        {
            "code" : "Tuk Tuk",
        "wheels":4
            "allowed":True
        }, 
        {
            "code" : "Bike",
        "wheels":4
            "allowed":False
        }]
user123987
  • 23
  • 5

1 Answers1

0

you can try like this

db.collectionName.find({"vehicles.code" : "car" }, {"vehicles.wheels" : 1 , "vehicles.allowed" : 1}).pretty() here "vehicles.code" : "car" is the filter and "vehicles.wheels" : 1 will display the only wheels value and won't display any other fields

Ranga Reddy
  • 54
  • 1
  • 7