CouchDB - Querying array key value for first key element only

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 03:55:24

问题


I have a couchdb view set up using an array key value, in the format:

[articleId, -timestamp]

I want to query for all entries with the same article id. All timestamps are acceptable.

Right now I am using a query like this:

?startkey=["A697CA3027682D5JSSC",-9999999999999]&endkey=["A697CA3027682D5JSSC",0]

but I would like something a bit simpler.

Is there an easy way to completely wildcard the second key element? What would be the simplest syntax for this?


回答1:


First, as a comment pointed out, there is indeed a special value {} that is ordered after any value, so your query becomes:

startkey=["target ID"]&endkey=["target ID",{}]

This is as equivalent to a wildcard match.

As a side note, there is no need to reverse the ordering in the map function by emitting a negative timestamp, you can reverse the order as an option to the view invocation (your start and end key will be swapped).

startkey=["target ID",{}]&endkey=["target ID"]&descending=true


来源:https://stackoverflow.com/questions/11623154/couchdb-querying-array-key-value-for-first-key-element-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!