我需要获取Archery
的数组列表中games
存在的文档。我该如何使用CouchDB选择器?
[{
"name": "John",
"games": ["Archery", "Board sports"]
},
{
"name": "Sara",
"games": ["Fishing", "Archery"]
},
{
"name": "Tara",
"games": ["Decathlon"]
}]
答案 0 :(得分:1)
您可以使用$elemMatch
:
{
"selector": {
"games": {
"$elemMatch": {
"$eq": "Archery"
}
}
}
}
它将返回games
字段等于“ Archery”的所有对象