Multiple key ranges as parameters to a CouchDB view

后端 未结 3 481
渐次进展
渐次进展 2021-01-11 13:42

The underlying problem - let\'s say my documents have \"categories\" and timestamps. If I want all documents in the \"foo\" category that have a t

相关标签:
3条回答
  • 2021-01-11 14:31

    Your probably better off just doing two queries. CouchDB can handle multiple simultaneous queries pretty well so spin off several processes/threads and query for foo and bar docs seperately.

    CouchDB does not currently support multiple range queries. ORing and ANDing keys is pretty much not doable in one query.

    0 讨论(0)
  • 2021-01-11 14:39

    There is a CouchDB issue request to let you do just that. I've attached a simple, no guarantees patch to 0.10.1 to that ticket which may work for you. It works for me and lets me do things like:

    {
        "keys": [
            {
                "startkey": ["0240286524","2010","03","01"],
                "endkey": ["0240286524","2010","03","07",{}]
            },
            {
                "startkey": ["0442257276","2010","03","01"],
                "endkey": ["0442257276","2010","03","07",{}]
            }
        ]
    }
    

    in the POST body, which lets me get all the data across multiple tracking ids, for a range of dates. I call with group=true&group_level=1 to have the results grouped by tracking id. Deeper group levels would allow me to group by tracking id|year, tracking id|year|month etc.

    Multiple connections were an unscalable overhead for me as I'd be looking to make 2000 concurrently :) (No, a new view is not an option - we're already at 400GB for data plus one view!)

    The issue and patch is at https://issues.apache.org/jira/browse/COUCHDB-523 .

    0 讨论(0)
  • 2021-01-11 14:39

    This has been added in newer versions of CouchDB. To add multiple ranges of start/end keys, you can use a POST request to your view, with a body that looks something like this:

    {
      "queries": [
        { "startkey": 10, "endkey": 11 },
        { "startkey": 16, "endkey": 18 }
      ]
    }
    

    I know it's an old question but I initially found it when I was looking for exactly this!

    0 讨论(0)
提交回复
热议问题