简体   繁体   English

如何在Springboot中使用elemMatch查询数组的元素,以使该数组只有一列,而该列没有字段名?

[英]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.

相关问题 如何检查 JsonNode 是否有数组 - Java, SpringBoot - How to check if JsonNode has array - Java, SpringBoot 如何检查矩阵(数组)是否具有与行相同的列 - How to check if an matrix (array) has a column that it's the same than a row SQL查询可能返回具有多个具有相同名称的列的结果集 - Possibility of SQL query to return a result set that has more than one column with the same name 如何使用二进制搜索来查找具有一定权重的数组中的第一个元素(另一个数组中的另一个元素)? - How to use binary search in order to find the first element in an array that has certain weight (another element in a different array)? SQL 查询从 postgresql 数据库表中具有数组数据类型的列中获取数据 - SQL query to fetch the data from the column which has array datatype in postgresql database table 列名在springboot中无效 - The column name is not valid in springboot 一列数组SQLite - One Column to Array SQLite 当数组的元素之一具有不正确的值时,如何使 Jackson 不会失败整个反序列化过程? - How to make Jackson not fail whole deserialziation process when one of the element of array has inproper value? supercsv如何通过列名获取列值数组 - supercsv how to get column value array by column name 如何在Java中迭代一列的字符串数组 - How to iterate string array for one column in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM