Reputation: 2996
I use SpringData. I have document with subdocument, it looks like :
{ "name" : "MongoDB", "type" : "database", "count" : 1, "info" : { x : 203, y : 102 } }
How can I find all documents with(for example) x=203 Thanks!
Upvotes: 1
Views: 2420
Reputation: 942
There is no way you can get subdocument directly. What you can do is use below query to match the value inside you subdocument. This would retrieve parent document if you criteria for the subdocument succeeds.As Rohit mentioned you can use below query but this return the type of your parent document
mongoTemplate.find(new Query(Criteria.where("info.x").is(203))), ParentDocument.class));
Upvotes: 4