简体   繁体   English

在mongodb子文档中查找

[英]Find in mongodb subdocument

I use SpringData. 我使用SpringData。 I have document with subdocument, it looks like : 我有子文档的文档,它看起来像:

{ "name" : "MongoDB", "type" : "database", "count" : 1, "info" : { x : 203, y : 102 } } {“name”:“MongoDB”,“type”:“database”,“count”:1,“info”:{x:203,y:102}}

How can I find all documents with(for example) x=203 Thanks! 如何找到所有文件(例如)x = 203谢谢!

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 如果您的子文档的条件成功,这将检索父文档。如Rohit提到您可以使用下面的查询,但这将返回您的父文档的类型

mongoTemplate.find(new Query(Criteria.where("info.x").is(203))), ParentDocument.class));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM