[英]How to use elemMatch in Springboot to query an element of an array such that the array has just one column and the column has no field name?
The table I am having is of the following form 我所拥有的表格具有以下形式
{
"element_1": 1,
"element_2": 1,
"elements":[
"ele_1", "ele_2", "ele_3", "ele_4"
]
},
{
"element_1":2,
"element_2":2,
"elements":[
"ele_5", "ele_6", "ele_7", "ele_8"
]
},
{
"element_1": 3,
"element_2": 3,
"elements": [
"ele_9", "ele_10", "ele_11", "ele_12"
]
}
Over here I wanted to query out the document having the element ele_1
in the elements
field so that on using the java command 在这里,我想查询出
elements
字段中具有元素ele_1
的文档,以便使用java命令
Query query = new Query("Required Criteria");
the document which should get returned should be 应退回的文件应为
{
"element_1": 1,
"element_2": 1,
"elements":[
"ele_1", "ele_2", "ele_3", "ele_4"
]
}
I would like to mention again that the arrays in the field "elements" have no field name hence providing a key parameter while building the Criteria object is not possible. 我想再次提及,“元素”字段中的数组没有字段名称,因此在构建Criteria对象时无法提供关键参数。 How to get the required result?
如何获得所需的结果?
you can simply write : 您可以简单地写:
Query query = new Query("{'elements' : 'ele_1'}");
You dont need $elemMatch
您不需要
$elemMatch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.