user2093576
user2093576

Reputation: 3092

querying nested JSON in mongodb using find

My JSON is:

db.col.insert([

    {
        "1":[
            {
                "a":"1",
                "b":"2",
                "v":"12"
            }
        ]
    },
    {
        "2":[
            {
                "a":"12",
                "v":"451"
            }
        ]
    }])

when I query using

db.col.find("1")

It is returning both the rows instead of the condition. how can i select just one row here?

Upvotes: 0

Views: 490

Answers (1)

Parvin Gasimzade
Parvin Gasimzade

Reputation: 26012

You can filter the data by checking if the given field exists using $exists keyword as follows :

db.col.find({1 : {$exists:true}})

Upvotes: 1

Related Questions