Creating view in Cloudant (CouchDB) based on an object property value

后端 未结 3 1369
心在旅途
心在旅途 2021-01-06 04:21

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

3条回答
  •  一向
    一向 (楼主)
    2021-01-06 04:59

    Cloudant's search works at the granularity of returning a document. Your indexing function could index the categories in use across the items in the document and then your search would return the documents containing items with the category you mention. Your application code would then need to filter down to the items to return to the client.

    Your index function would be something like (shamelessly cribbing from Wintamute):

    if (!doc.items || doc.items.length === 0) return;
    var item;
    for (var i=0; i

    The alternative is to break out the items into their own documents if you really want to be able to get just the items.

    However, I'd second (and have up-voted) Wintamute's answer as I agree that the suggested view is the best solution in this specific case (find and display items by cat).

提交回复
热议问题