我一直在試圖找到這個需求的解決方案,但我已經擊中了很多死衚衕。基於對象屬性值在Cloudant(CouchDB)中創建視圖
我正在使用Cloudant作爲我的用戶文檔的數據存儲。每個用戶文檔都有一個名爲'items'的字段(屬性),它是一個對象數組。
所以用戶文件看起來是這樣的:
{
"_id":"userid1",
"_rev":"XX",
"username": "foobaruser"
"items":
[
{
"date":1357879144069,
"text":"don't cry because it's over, smile because it happened.",
"cat":"determination"
},
{
"date":1357879179209,
"text":"those who mind don't matter, and those who matter don't mind.",
"cat":"fitness"
},
{
"date":1357883809736,
"text":"be the change that you wish to see in the world.",
"cat":"determination"
},
{
"date":1357879179209,
"text":"those who mind don't matter, and those who matter don't mind.",
"cat":"hardwork"
},
{
"date":1357879179209,
"text":"those who mind don't matter, and those who matter don't mind.",
"cat":"determination"
}
]
}
- 有在數據存儲這樣的多個用戶的文件和每個文件都有屬性「項」
要求:
理想情況下,我想在視圖上使用搜索功能併爲「貓」傳遞一個值,然後返回與「貓」值相匹配的所有文檔中的所有「項目」。
例如 https:// [username] .cloudant.com/dbname/_design/views/_search/doc?q =確定
上述搜索將返回所有用戶文檔中「items」貓=決心」的格式與此類似:
{ "total_rows": 2, "rows": [{ "id": "userid1", "items": [ { "date":1357879144069, "text":"don't cry because it's over, smile because it happened.", "cat":"determination" }, { "date":1357883809736, "text":"be the change that you wish to see in the world.", "cat":"determination" }, { "date":1357879179209, "text":"those who mind don't matter, and those who matter don't mind.", "cat":"determination" } ] }, { "id": "userid2", "items": [ { "date":135787966655, "text":"Some text", "cat":"determination" } ] }] }
如果使用是不可能的‘搜索’,則是有可能使用次級索引來實現這一目標?
你試試吧:
您可以在搜索作爲查詢呢?如果它沒有做你想做的事,你需要創建一個視圖。 – WiredPrairie 2013-05-01 11:17:23
對不起,不知道你的意思。我嘗試了什麼? – newbreedofgeek 2013-05-01 23:36:56
您是否嘗試過搜索?它可能適合您的需求(並且您處於最佳位置嘗試它並查看它是否有效)。 – WiredPrairie 2013-05-02 01:14:28