-1

Following is structure of my mongo document and I want to search all such documents for which w is true.

w is key of first element in array cd

/* 1 */
{
    "_id" : ObjectId("55cc9bd9e4b07c05e5812de7"),
    "_class" : "com.test.MyClass",
    "cd" : [ 
        {
            "d" : 54.6199989318847660,
            "w" : "true",
            "x" : "false",
        
        }
    ],
    "sts" : "READ"
}

FYI: I am using Spring Mongo Template to connect to DB

swapy
  • 290
  • 2
  • 9

1 Answers1

0

You should use dot notation to compare the specific element of the array. If you need the w property of the first element of cd array, it will be like this:

db.collectionName.find({"cd.0.w":true})

See more at mondoDB tutorial page

Alexander Korzhykov
  • 1,063
  • 10
  • 14