CouchDB-仅查询第一个键元素的数组键值 [英] CouchDB - Querying array key value for first key element only

查看:89
本文介绍了CouchDB-仅查询第一个键元素的数组键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用数组键值设置的沙发状视图,格式为:

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

[articleId, -timestamp]

我要查询具有相同文章ID的所有条目。所有时间戳都是可接受的。

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]

但是我想简单一些。

有没有一种简单的方法可以完全通配第二个关键元素?最简单的语法是什么?

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

推荐答案

首先,正如注释所指出的,确实存在一个特殊值 {} ,该值在任何值之后排序,因此您的查询将变为:

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",{}]

请注意,不需要通过发出负时间戳来反转map函数中的顺序,您可以反转订单作为视图调用的选项(您的开始键和结束键将被交换)。

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

这篇关于CouchDB-仅查询第一个键元素的数组键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆