In the MongoDB Documentation we’ve got the following example:
db.factories.insert( { name: "xyz", metro: { city: "New York", state: "NY" } } );
db.factories.ensureIndex( { metro : 1 } );
// this query can use the above index:
db.factories.find( { metro: { city: "New York", state: "NY" } } );
I’m currently looking for a solution to archieve this query in spring data. My first approach was
Query.query(Criteria.where("metro")
.andOperator(Criteria.where("city").is("New York")
.and("state").is("NY")))
but this results in the following query
{ "metro" : { } , "$and" : [ { "city" : "New York" , "state" : "NY"}]}
Finally i found the solution by fiddling around:
Hopefully this is the right way to do it…