【问题标题】:Can't any CouchDB _list function to work任何 CouchDB _list 函数都不能工作
【发布时间】:2023-03-29 14:28:02
【问题描述】:

努力让任何列表功能正常工作。我对 _show 和 _view 函数没问题,但列表似乎不起作用,或者我误解了该怎么做! (我承认需要一个白痴的指南!)

我的设计文档如下:

{
   "_id": "_design/lists",
   "_rev": "3-d22225b4a28a6ca11484723c3a37201b",
   "language": "javascript",
   "views": {
       "variants": {
           "map": "function(doc) { emit(doc.var, doc.number_of_results); }"
       }
   },
   "lists": {
       "results": "function(head, req) { var row; while(row = getRow()) {send(row.value);}}"
   }
}

当我输入 http://localhost:5984/mydb/_design/lists/_view/variants 时,我会得到一个变体名称列表,例如:

...{"id":"f050ad9b9f725443cb8c4071f40583b","key":"rs1013940","value":19008},
{"id":"f050ad9b9f725443cb8c4071f40daff","key":"rs1013940","value":19008},
{"id":"f050ad9b9f725443cb8c4071f40b985","key":"rs1021188","value":10197}...

但是当我输入 http://localhost:5984/mydb/_design/lists/_list/results 我得到:

{"error":"list_error","reason":"Invalid path."}

有谁知道我做错了什么?我已经尝试了所有我能想到的方法,并从任何在线教程中更换了该功能。

我在 Ubuntu 12.04 上使用 CouchDB 1.0.1 版

非常感谢,希望有人能帮忙!

【问题讨论】:

  • 当您使用 IBM Cloudant 时,同样的问题也适用 - 到目前为止,我还不知道 Cloudant 是基于 CouchDb 的

标签: list views couchdb document


【解决方案1】:

您需要在 URL 中同时包含视图名称和列表名称:

http://localhost:5984/:db/_design/:ddoc/_list/:list/:view

在你的情况下翻译为:

http://localhost:5984/mydb/_design/lists/_list/results/variants

【讨论】:

    【解决方案2】:

    我也有同样的难题;从初学者的角度来看,要立即辨别使用视图、节目和列表的区别并不容易。在官方文档中我读到了这个:

    While Show functions are used to customize document presentation, List functions are used for same purpose, but against View functions results.

    这让我有点困惑。我同样认为一个人可以单独使用一个列表来整理文档,也许是在一个漂亮的多汁 HTML 涂层中,但我真的只是在阅读了权威指南的这一页后才弄清楚发生了什么(这是一个令人难以置信的资源!)

    http://guide.couchdb.org/draft/transforming.html

    就像 Dominic 所说,基于 API 对我来说应该很明显 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      • 2017-09-19
      • 1970-01-01
      • 2014-01-10
      相关资源
      最近更新 更多