[CouchDB查询选择器在元素数组中的字符串上

问题描述 投票:1回答:1

我需要获取Archery的数组列表中存在games的文档。如何使用CouchDB选择器?

[{
    "name": "John",
    "games": ["Archery", "Board sports"]
},
{
    "name": "Sara",
    "games": ["Fishing", "Archery"]
},
{
    "name": "Tara",
    "games": ["Decathlon"]
}]
couchdb
1个回答
0
投票

您可以使用$elemMatch

{
   "selector": {
      "games": {
         "$elemMatch": {
            "$eq": "Archery"
         }
      }
   }
}

它将返回games字段包含“ Archery”的所有对象

© www.soinside.com 2019 - 2024. All rights reserved.