如何在 couchDB 视图中添加空的 startkey 数组索引?

发布于 2025-01-16 07:25:49 字数 609 浏览 2 评论 0原文

目前我正在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我纯我任性 2025-01-23 07:25:49

是的,通过使用 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 use null 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 emit doc._id rather than doc.id.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文