更新时间:2022-06-25 09:27:06
This is a lot like my response at Cloudant Selector Query but here's the deal, applied to your question:
运行此查询的最简单方法是使用"Cloudant Query"(或"Mango",在即将发布的CouchDB 2.0版本中称为"Mango"),而不是CouchDB中的传统MapReduce视图索引系统. (此博客涵盖了以下差异: https://cloudant.com/blog/mango-json-vs-text-indexes/,这是一个概述:
The easiest way to run this query is using "Cloudant Query" (or "Mango", as it's called in the forthcoming CouchDB 2.0 release) -- and not the traditional MapReduce view indexing system in CouchDB. (This blog covers the differences: https://cloudant.com/blog/mango-json-vs-text-indexes/ and this one is an overview: https://developer.ibm.com/clouddataservices/2015/11/24/cloudant-query-json-index-arrays/).
您的CQ索引应如下所示:
Here's what your CQ index should look like:
{
"index": {
"fields": [
{"name": "Teams.[].id", "type": "string"}
]
},
"type": "text"
}
随后的查询如下:
{
"selector": {
"Teams": {"$elemMatch": {"id": "79d25d41d991890350af672e0b76faed"}}
},
"fields": [
"_id",
"FirstName",
"LastName"
]
}
您可以在Cloudant仪表板的查询"部分中自行尝试,也可以通过curl进行如下操作:
You can try it yourself in the "Query" section of the Cloudant dashboard or via curl with something like this:
curl -H "Content-Type: application/json" -X POST -d '{"selector":{"Teams":{"$elemMatch":{"id":"79d25d41d991890350af672e0b76faed"}}},"fields":["_id","FirstName","LastName"]}' https://broberg.cloudant.com/teams_test/_find
该数据库是世界可读的,因此您可以在此处查看我在其中创建的示例文档:
That database is world-readable, so you can see the sample documents I created in there here: https://broberg.cloudant.com/teams_test/_all_docs?include_docs=true
挖出Seinfeld主题:D
Dig the Seinfeld theme :D