我需要获取games
数组列表中存在Archery
的文档。我该如何使用 CouchDB 选择器?
[{
"name": "John",
"games": ["Archery", "Board sports"]
},
{
"name": "Sara",
"games": ["Fishing", "Archery"]
},
{
"name": "Tara",
"games": ["Decathlon"]
}]
最佳答案
您可以使用$elemMatch
:
{
"selector": {
"games": {
"$elemMatch": {
"$eq": "Archery"
}
}
}
}
它将返回所有 games
字段等于“Archery”的对象
关于CouchDB 元素数组中字符串的查询选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55169530/