I've been trying to find a solution for this requirement but I've hit many dead ends.
I'm using Cloudant as my data store of user documents. Each user document has a field (property) called 'items', which is an array of objects.
So a user document looks like this:
{
"_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"
}
]
}
- There are multiple user documents like this in the data store and each document has the property "items"
Requirement:
Ideally, i'd like to use a search function on a view and pass in a value for "cat", which then returns all the "items" in all docs that match the value of "cat".
e.g. https://[username].cloudant.com/dbname/_design/views/_search/doc?q=determination
The above search will return all the objects in "items" across all user docs which have "cat = determination" in a format similar to this:
{ "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" } ] }] }
If this is not possible using "search", then is it possible to use secondary-indexes to achieve this?