按嵌套数组内容的Cloudant/CouchDB查询

按嵌套数组内容的Cloudant/CouchDB查询,couchdb,cloudant,Couchdb,Cloudant,在我的cloudant数据库中,我有这样的对象。我想查询基于嵌套数组中属性的对象 在下面的示例中,如何查询有userId==“user1”投票的所有对象?查询应返回这两个对象。当我搜索userId“user2”时,它应该返回第一个,因为第二个对象只有user1和user4的投票权 { "_id": "1", "votes": [ { "userId": "user1", "comment": "" }

在我的cloudant数据库中,我有这样的对象。我想查询基于嵌套数组中属性的对象

在下面的示例中,如何查询有userId==“user1”投票的所有对象?查询应返回这两个对象。当我搜索userId“user2”时,它应该返回第一个,因为第二个对象只有user1和user4的投票权

{
    "_id": "1",
    "votes": [
        {
            "userId": "user1",
            "comment": ""
        },
        {
            "userId": "user2",
            "comment": ""
        },
        {
            "userId": "user3",
            "comment": ""
        }
    ]
}

{
    "_id": "2",
    "votes": [
        {
            "userId": "user1",
            "comment": ""
        },
        {
            "userId": "user4",
            "comment": ""
        }
    ]
}

此视图将返回按userId排序的所有投票列表(其中投票是userId和_id),以仅获取user1 use?key=“user1”

功能(doc){
对于(我在文件中投票)
emit(doc.voces[i].userId,doc.\u id);
}
/dbName/_design/foo/_view/bar?key=“user1”


此视图将返回按userId排序的所有投票列表(其中投票是userId和_id),以仅获取user1 use?key=“user1”

功能(doc){
对于(我在文件中投票)
emit(doc.voces[i].userId,doc.\u id);
}
/dbName/_design/foo/_view/bar?key=“user1”

{"total_rows":5,"offset":0,"rows":[
{"id":"1","key":"user1","value":"1"},
{"id":"2","key":"user1","value":"2"}
]}