Couchdb 更新处理程序

发布于 2024-12-05 06:09:57 字数 868 浏览 0 评论 0原文

以下:CouchDB 文档更新处理程序(就地更新) 和 < a href="http://wiki.apache.org/couchdb/Document_Update_Handlers" rel="nofollow noreferrer">http://wiki.apache.org/couchdb/Document_Update_Handlers

我正在尝试创建自己的函数,暂时增加一个整数,但我得到:

{"error": "bad_request","re​​ason":"附件名称不能以 '_' 开头"}

我的设计文档如下所示:_design/db

  "check": {
        "increment": "function(doc,req){ var channel = req.query.channel; doc.channels[0].sp = doc.channels[0].sp+1;  return[channel, 'check']}"
    }

请求如下:

curl -X PUT https://server/db/_design/db/_check/increment/channels?channel=foo

我不太明白我的意思米做错了,如果我删除 '_',我会得到:

{"error":"conflict","re​​ason":"文档更新冲突。"}

谢谢

Following: CouchDB Document Update Handlers (in-place updates) and http://wiki.apache.org/couchdb/Document_Update_Handlers

I'm trying to create my own function which increment an integer for now, but I'm getting:

{"error":"bad_request","reason":"Attachment name can't start with '_'"}

My design document looks like: _design/db

  "check": {
        "increment": "function(doc,req){ var channel = req.query.channel; doc.channels[0].sp = doc.channels[0].sp+1;  return[channel, 'check']}"
    }

And the request is like:

curl -X PUT https://server/db/_design/db/_check/increment/channels?channel=foo

I don't understand very well what I'm doing wrong, if I remove the '_' I will get:

{"error":"conflict","reason":"Document update conflict."}

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

甜宝宝 2024-12-12 06:09:57

我认为你的要求是错误的。尝试这样的操作:

curl -X PUT https://server/db/_design/db/_update/increment/channels?channel=foo

其次,您的更新处理函数应该直接位于设计文档中的“更新”键中(因此不作为任何视图的一部分)。所以你的设计文档应该是这样的:

{
    "_id": "_design/doc",
    "updates": {
        "increment": "function(doc,req){ var channel = req.query.channel; doc.channels[0].sp = doc.channels[0].sp+1;  return[channel, 'check']}"
    }
}

Your request is wrong, I think. Try something like this:

curl -X PUT https://server/db/_design/db/_update/increment/channels?channel=foo

Second, your update handler function should be in an "updates" key directly in the design document (so not as part of any view). So your design document should look like this:

{
    "_id": "_design/doc",
    "updates": {
        "increment": "function(doc,req){ var channel = req.query.channel; doc.channels[0].sp = doc.channels[0].sp+1;  return[channel, 'check']}"
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文