这是我想出的一种方法来执行更新和删除。
我用纳米API:
包括由 VAR纳米=需要( '纳米')(纳米的 'https://'+dbCredentials.user+': '+ dbCredentials.password +' 主机名:端口/” ); 请确保把正确的用户名和密码
对于更新
更新 - 你需要使用插入API只,但正确的_id和_eval和变化。例如:
nanodb.insert({ "_id": "3a1cc8c7f955f895131c3289f5144eab", "_rev": "2- 7040205a1c9270ad696724458399ac94", "name": "Tom", "employername":"Google"}, function(err, body, header) {
if (err) {
console.log('[db.insert] ', err);
return;
}
console.log('you have inserted the rabbit.')
console.log(body);
});
上述代码将对给定的id和_rev执行更新。将会有一个新的修订版本号更新,并且id将保持不变。如果您错过了ID或版本号,它会引发冲突错误。
对于删除 简单使用nano.destroy与ID和版本号
nanodb.destroy("3a1cc8c7f955f895131c3289f5144eab","3-3e39e2298f109414cef1310449e0fd5c",function(err, body, header) {
if (err) {
console.log('[db.insert] ', err);
return;
}
console.log('you have inserted the rabbit.')
console.log(body);
});
采用纳米状框架API比通过HTTP进行REST API调用来访问数据库cloudant更好。
希望这有助于想连接到NodeJS的Cloudant db的人
要删除的文件来看看这http://stackoverflow.com/questions/32103420/deleting-a -document-from-cloudant-database-in-nodejs/37006669#37006669 –