Jürgen Paul
Jürgen Paul

Reputation: 14997

Check if an array key in a field exists in mongo

{
 "_id": ObjectId("502626aad4ebdf600b000000"),
 "created_at": ISODate("2012-08-11T09: 32: 26.0Z"),
 "excerpt": "lotto results for August 11, 2012",
 "results": {
    "1-digit" : {
        "0" : "1",
    },
    "2-digit" : {
        "0" : "1",
        "1" : "2",
    },
    "3-digit" : {
        "0" : "1",
        "1" : "2",
        "2" : "3",
    }
    }
}

How should I check if results.1-digit exists?

Upvotes: 2

Views: 5713

Answers (2)

Sushil
Sushil

Reputation: 1288

Adding quotes are as important in shell I believe

{"results.1-digit" : {$exists : true }}  

Upvotes: 1

Alexey Ogarkov
Alexey Ogarkov

Reputation: 2916

You can run query {results.1-digit : {$exists : true }}

Hope it helps.

Upvotes: 9

Related Questions