如何在 couchDB 视图中添加空的 startkey 数组索引?
目前我正在将 hyperledger 结构与 couchDB 容器一起使用。我有一个 CouchDB 视图:
function (doc) {
if(doc.groups.length > 0) {
doc.groups.forEach(function (tag) {
emit([doc.id, tag.fname, tag.lname, tag.no], tag);
});
}
}
我想使用 start & 来过滤数据。结束键。
我们可以在 startkey 数组中使用空索引来过滤视图吗?
这是相同的示例:
http://0.0.0.0:7984/mychannel_team/_design/team_view/_view/team_view_filter
?skip=0&limit=21&reduce=false&startkey=[1,"isha",{},"45"]&endkey=[1,"isha",{},"45"]
Currently I'm using hyperledger fabric with couchDB container. I have a CouchDB view :
function (doc) {
if(doc.groups.length > 0) {
doc.groups.forEach(function (tag) {
emit([doc.id, tag.fname, tag.lname, tag.no], tag);
});
}
}
I want to filter data using the start & end keys.
Can we use an empty index in startkey array for filter on view?
Here is example for the same:
http://0.0.0.0:7984/mychannel_team/_design/team_view/_view/team_view_filter
?skip=0&limit=21&reduce=false&startkey=[1,"isha",{},"45"]&endkey=[1,"isha",{},"45"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,通过使用
startkey=[""]
查询视图。也可以使用null
(3.2.2.5。请注意,参数
startkey=[1,"isha",{},"45"]&endkey=[1,"isha",{},"45"]
在感觉
{}
的使用似乎暗示着通配符,但事实并非如此。这些参数相当于之前的
startkey=[1,"isha",{}]&endkey=[1,"isha",{}]
因为
{} 后面的任何字段值
被忽略。将{}
视为匹配所有内容,而不是字段/占位符通配符。另一件事:对于OP的map函数,复杂键的第一个字段将始终为
null
。其意图很可能是发出doc._id
而不是doc.id
。Yes, by querying the view with
startkey=[""]
. One could usenull
too (3.2.2.5. Collation Specification).Do note the parameters
startkey=[1,"isha",{},"45"]&endkey=[1,"isha",{},"45"]
is poorly constructed in the sense that the use of
{}
seems to imply a wildcard, which is does not.These parameters are equivalent to the prior
startkey=[1,"isha",{}]&endkey=[1,"isha",{}]
Because any field value following
{}
is ignored. Think of{}
as a match-all, not a field/placeholder wildcard.As another matter: regarding the OP's map function, the first field of the complex key will always be
null
. It is probable the intention is to emitdoc._id
rather thandoc.id
.