从Node.js中的Cloudant数据库中删除文档

编程入门 行业动态 更新时间:2024-10-26 20:28:07
本文介绍了从Node.js中的Cloudant数据库中删除文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这可能是一个基本问题,但我浏览了github Cloudant库和Cloudant文档,并提到了从数据库中删除特定文档的情况,但从未进行彻底解释。非常令人沮丧我最想删除文档的方法是使用http请求,而不是Cloudant库提供的功能,即使我正在通过_rev传递文档,我也不断收到文档更新冲突。谁能解释使用nodejs从Cloudant数据库中删除文档的示例,以帮助您解决该问题。谢谢。

This may be a basic question but I've looked through the github Cloudant library and the Cloudant documentation and deleting a specific document from the database is mentioned but never thoroughly explained. It's very frustrating. The closest I've gotten to deleting a document is using an http request rather then the functions Cloudant library offers and I continuously get a "Document Update Conflict" even though I'm passing through the _rev of the document. Can anybody explain deleting a document from a Cloudant database using nodejs with an example to help sort this out. Thanks.

推荐答案

您可以使用destroy 方法= github/apache/couchdb-nano#document-functions rel = nofollow title = nano> nano 就像@JakePeyser所说的那样,而不是使用http API,因为使用nodejs。 但是由于您正在发送_rev并收到文档更新冲突错误,这使我怀疑您是否拥有最新的_rev。如果本地_rev与远程_rev不匹配,则通常会发生文档更新冲突。因此,我建议将 destroy 函数包装在 get 函数中。因此,对@JakePeyser的示例进行的更新将是:

You can use the destroy method of nano like @JakePeyser has said, instead of using http APIs since you are using nodejs. But since you are sending _rev and getting a "Document Update Conflict" error, it leads me to doubt if you have the latest _rev with you. "Document Update Conflict" happens mostly if the local _rev doesn't match the remote _rev. I would therefore suggest wrapping your destroy function in a get function. So an update to @JakePeyser's example would be:

var nano = require("nano")("cloudantURL"), db = nano.db.use("yourDB"); db.get(docUniqueId, function(err, body) { if (!err) { var latestRev = body._rev; db.destroy(docUniqueId, latestRev, function(err, body, header) { if (!err) { console.log("Successfully deleted doc", docUniqueId); } }); } })

更多推荐

从Node.js中的Cloudant数据库中删除文档

本文发布于:2023-10-19 00:04:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1505819.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   文档   Node   js   Cloudant

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!