如何使 $elemMatch 为芒果查询中的 json 数组数据工作?
How to make $elemMatch work for json array data in mango query?
我的应用程序中有一个如下所示的字段。
{
"Ct": "HH",
Val:{
"Count":"A",
"Branch":"A"
}
}
当我尝试在 CouchDB 中使用以下命令检索此记录时,我无法检索记录。
{
"selector" : {
"Val":{
"$elemMatch":{
"Count":"A"
}
}
}
来自 CouchDB 文档,$elemMatch
[1]
Matches and returns all documents that contain an array field with at
least one element that matches all the specified query criteria.
Val.Count
不是数组字段,因此 $elemMatch
不合适。
考虑有关子字段查询的 CouchDB 文档[2]:
1.3.6.1.3. Subfields
A more complex selector enables you to specify the values for field of
nested objects, or subfields. For example, you might use a standard
JSON structure for specifying a field and subfield.
Example of a field and subfield selector, using a standard JSON
structure:
{
"imdb": {
"rating": 8
}
}
An abbreviated equivalent uses a dot notation to combine the field and
subfield names into a single name.
{
"imdb.rating": 8
}
具体来说,
selector: {
"Val.Count": "A"
}
1 CouchDB: 1.3.6.1.7. Combination Operators
2 CouchDB: 1.3.6.1.3. Subfields
我的应用程序中有一个如下所示的字段。
{
"Ct": "HH",
Val:{
"Count":"A",
"Branch":"A"
}
}
当我尝试在 CouchDB 中使用以下命令检索此记录时,我无法检索记录。
{
"selector" : {
"Val":{
"$elemMatch":{
"Count":"A"
}
}
}
来自 CouchDB 文档,$elemMatch
[1]
Matches and returns all documents that contain an array field with at least one element that matches all the specified query criteria.
Val.Count
不是数组字段,因此 $elemMatch
不合适。
考虑有关子字段查询的 CouchDB 文档[2]:
1.3.6.1.3. Subfields
A more complex selector enables you to specify the values for field of nested objects, or subfields. For example, you might use a standard JSON structure for specifying a field and subfield.
Example of a field and subfield selector, using a standard JSON structure:
{ "imdb": { "rating": 8 } }
An abbreviated equivalent uses a dot notation to combine the field and subfield names into a single name.
{ "imdb.rating": 8 }
具体来说,
selector: {
"Val.Count": "A"
}
1 CouchDB: 1.3.6.1.7. Combination Operators
2 CouchDB: 1.3.6.1.3. Subfields