元素数组中字符串的 CouchDB 查询选择器
CouchDB query selector on string in array of elements
我需要获取 games
数组列表中存在 Archery
的文档。我如何使用 CouchDB 选择器?
[{
"name": "John",
"games": ["Archery", "Board sports"]
},
{
"name": "Sara",
"games": ["Fishing", "Archery"]
},
{
"name": "Tara",
"games": ["Decathlon"]
}]
您可以使用 $elemMatch
:
{
"selector": {
"games": {
"$elemMatch": {
"$eq": "Archery"
}
}
}
}
它将 return 所有 games
字段等于 'Archery'
的对象
我需要获取 games
数组列表中存在 Archery
的文档。我如何使用 CouchDB 选择器?
[{
"name": "John",
"games": ["Archery", "Board sports"]
},
{
"name": "Sara",
"games": ["Fishing", "Archery"]
},
{
"name": "Tara",
"games": ["Decathlon"]
}]
您可以使用 $elemMatch
:
{
"selector": {
"games": {
"$elemMatch": {
"$eq": "Archery"
}
}
}
}
它将 return 所有 games
字段等于 'Archery'