Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何使用nodejs cloudant模块更新cloudant中的数据?_Json_Node.js_Couchdb_Cloudant - Fatal编程技术网

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

Json 如何使用nodejs cloudant模块更新cloudant中的数据?,json,node.js,couchdb,cloudant,Json,Node.js,Couchdb,Cloudant,下面提到了示例json文档。它包含两个字段 { "_id": "daef4a0e39c0c7a00feb721f6c4ce8b9", "_rev": "2-8c7ef28df59ecbdaa23b536e58691416", "name": "sukil", "skills": "java" } In server.js var express = require('express'); var app = express(); var cloudant = re

下面提到了示例json文档。它包含两个字段

{
  "_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);
})
})
这里_design/sample是一个设计文档名,inplace是update函数名,接下来是文档id。它返回的错误是文档更新冲突,响应未定义

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?

原子方法假定第一个参数仅作为设计文档。因此需要明确指定
“\u design”

这可能是导致问题的原因

alice.atomic("sample", "inplace", "daef4a0e39c0c7a00feb721f6c4ce8b9", {field: "name", value: "bar"}, function (error, response) {
 console.log(error+""+response);
})