简体   繁体   English

您如何在Mongo中诊断write_concern问题?

[英]How do you diagnose write_concern problems in Mongo?

I have a Mongo database (v2.4.10) setup with a secondary and I'm saving data to it. 我有一个带有辅助数据库的Mongo数据库(v2.4.10)设置,我正在向其中保存数据。 Occassionally after saving a new document and trying to retrieve it I get an exception for the document not being found, even though on manual inspection it's there. 保存新文档并尝试对其进行检索后,偶尔会发现找不到该文档的异常,即使经过手动检查也是如此。

Here's a minmal example but unfortunately the problem does not reproduce consistently. 这是一个简单的示例,但是不幸的是,问题并没有始终如一地重现。 I suspect the problem due to trying to read from the database before the secondary has a copy of the data? 我怀疑是由于尝试在辅助数据库具有数据副本之前从数据库读取数据而引起的问题?

from mongoengine import connect, Document

class User(Document):
    date_creation = DateTimeField(default=datetime.datetime.utcnow)
    username = StringField(required=True, unique=True)

user = User()
user.username = 'nick'
user.save()

user = User.objects.get(username='nick') # exception thrown here matching User not found
user.username = 'changed'
user.save()

Is there a way to diagnose whether this is true? 有没有办法诊断这是否正确? Is so what is the recommended solution should I just be calling user.save(write_concern={'w':0}) 是的,我应该打电话给user.save(write_concern={'w':0})的推荐解决方案是什么

使用save(...,write_concern = {w:2,fsync:True},...),因为mongoengine的默认写入关注值为None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM