更新时间:2022-06-25 09:27:48
这很像我在 Cloudant 选择器查询 但这是适用于您的问题的交易:
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 版本中称为)——而不是 CouchDB 中传统的 MapReduce 视图索引系统.(此博客涵盖了差异:https://cloudant.com/blog/mango-json-vs-text-indexes/ 这是一个概述:https://developer.ibm.com/clouddataservices/2015/11/24/cloudant-query-json-index-arrays/).
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
该数据库是全球可读的,因此您可以在此处查看我在其中创建的示例文档:https://broberg.cloudant.com/teams_test/_all_docs?include_docs=true
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
挖掘宋飞主题:D