python couchdb 版本冲突
我有一个 python 程序,可以访问 couchDB 数据库、创建新文档并更新现有文档。 对于给定的数据库、db 和文档 Doc,我尝试在每次修改之前小心并重新加载文档:
somedoc = Doc.load(db,id)
在通过更新之前
doc.store(db)
据我所知,这不是必需的,因为每次都应该更新 doc.rev商店被称为。但是......我收到冲突消息:
couchdb.http.ResourceConflict: (u'conflict', u'Document update conflict.')
有什么方法可以强制不更新并显示警告消息,而不是在这些冲突上出现致命错误。或者,更好的是,是否有某种方法可以快速检查文档修订号 - 数据库正在由两个都更新的脚本访问,但两者都小心地加载每个文档,快速进行修改并在尽可能短的时间内更新数据库以尽量减少冲突的可能性......
干杯
I have a python program that accesses a couchDB database, creates new documents and updates existing ones.
For a given database, db, and document, Doc, I try to take care and reload the document before each modification:
somedoc = Doc.load(db,id)
before updating via
doc.store(db)
As far as I am aware this shouldn't be necessary, as doc.rev should be updated each time store is called. BUT ... I am getting conflict messages:
couchdb.http.ResourceConflict: (u'conflict', u'Document update conflict.')
Is there any way of just forcing no update and a warning message rather than having a fatal error upon these conflicts. Or, better, is there some way of quickly checking the document revision number - the db is being accessed by two scripts that both update, but both are careful to load each doc, make modifications quickly and update the db in as little time as possible to minimise the chance of a conflict....
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我仍然没有弄清楚资源冲突从何而来,考虑到在存储文档之前我检查修订是否正确:
但是,有一种简单的方法可以解决导致致命错误的冲突(对于 python 来说是新的,所以之前没有想过这样做):
这确实要求在 couchDB 抛出 ResourceConflict 时,在再次存储之前重做 try 命令之前对 doc 的任何更新。
I still haven't worked out where the resource conflict is coming from, given that just before storing a doc I check that the revision is correct:
However, there is an easy way round the conflict causing a fatal error (new to python, so didn't think of doing this before):
This does require that any updates to doc before the try command are redone before storing again when couchDB throws a ResourceConflict.
您是否检查过以确保在
存储
时更新了doc
的修订版本?我使用的库不会修改doc
,而是在成功存储
后返回新版本。编辑:我猜他们会编辑< code>doc:
此示例是使用
couchdbkit
生成的。Have you checked to make sure that
doc
's revision is updated when youstore
?Libraries I've used won't modifydoc
but instead return the new revision upon a successfulstore
.Edit: I guess they will edit
doc
:This sample was generated using
couchdbkit
.