這是我想出的一種方法來執行更新和刪除。
我用納米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 –