首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用nodejs cloudant模块更新cloudant中的数据?

如何使用nodejs cloudant模块更新cloudant中的数据?
EN

Stack Overflow用户
提问于 2015-01-31 18:19:42
回答 1查看 792关注 0票数 1

下面提到的示例json documents.It包含两个字段。

代码语言:javascript
复制
{
  "_id": "daef4a0e39c0c7a00feb721f6c4ce8b9",

  "_rev": "2-8c7ef28df59ecbdaa23b536e58691416",

  "name": "sukil",

  "skills": "java"
}


In server.js

var express = require('express');

var app = express();

var cloudant = require('cloudant');

cloudant({account:"test", password:"test"}, function(err, cloudant) {

var alice = cloudant.use('opti-update')
alice.atomic("_design/sample", "inplace", "daef4a0e39c0c7a00feb721f6c4ce8b9", {field: "name", value: "bar"}, function (error, response) {
 console.log(error+""+response);
})
})

这里的_ id.It /sample是设计文档名称,inplace是更新函数名,然后是document design returns error是文档更新冲突,response是未定义的响应。

代码语言:javascript
复制
In design document mentioned below

{
  "_id": "_design/sample",

  "_rev": "9-94393ee4665bdfd6fb283e3419a53f24",

  "updates": {

    "inplace": "function(doc,req){var field = req.body.field;var value = req.body.value;doc[field] = value;return [doc,''];}"

  }
}


I want to update the data in cloudant using node cloudant module. I want to update the name field in json document.Above method i tried but it shows document update conflict error.How to resolve this?
EN

回答 1

Stack Overflow用户

发布于 2015-04-20 16:06:36

原子方法仅将第一个参数假定为设计文档。所以需要显式指定"_design"

代码语言:javascript
复制
alice.atomic("sample", "inplace", "daef4a0e39c0c7a00feb721f6c4ce8b9", {field: "name", value: "bar"}, function (error, response) {
 console.log(error+""+response);
})

这可能是导致问题的原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28250514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档