如何进行文件的部分更新 [英] How to do partial update of a document

查看:95
本文介绍了如何进行文件的部分更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关如何更新CouchDB中的字段的指南。我尝试通过控制台卷曲,它可以正常工作,但以编程方式。我不知道如何更新特定字段(例如姓名)。这是在CouchDB中更新文档的片段,该片段可以正常工作并向我返回更新的修订版ID。

I need a guidance on how can I update a field in CouchDB. I tried curl via console it works fine but programatically. I don't understand how to update a particular field say 'name'. Here is the snippet of updating a document in CouchDB which works fine and returns me the updated revision id.

HttpPut httpPutRequest = new HttpPut(hostUrl +"/"+ docId);
StringEntity body = new StringEntity(jsonDoc.toString());
httpPutRequest.setEntity(body);

httpPutRequest.setHeader("Accept", "application/json");
httpPutRequest.setHeader("Content-type", "application/json");


推荐答案

CouchDB不支持部分更新。换句话说,要更新文档中的字段,必须更新本地JSON文档中的字段并将该文档作为一个整体推送到CouchDB。

Partial updates are not supported by CouchDB. In other words, to update a field in the document, you must update the field in your local JSON document and push that document to CouchDB as a whole.

您可以完成通过仍然发出HTTP PUT,确保文档中包含适当的_rev。

You can accomplish this by still issuing an HTTP PUT, ensuring the appropriate _rev is included in your document.

更多详细信息,请参见

More details are available in the wiki.

这篇关于如何进行文件的部分更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆