简体   繁体   English

几分钟后,保存在mongodb中的记录消失了

[英]records saved in mongodb disappeared after some minutes

Updated records got missing after awhile in mongodb 在mongodb中,一段时间后更新的记录丢失了

I tried to update a document in mongodb using java driver 3.6, st first the records got updated successfully. 我尝试使用java驱动程序3.6更新mongodb中的文档,st首先成功更新了记录。 but after 1 minutes those records value turned to an empty string 但是1分钟后,这些记录值变为空字符串

A = new A();
            BasicDBObject searchQuery = new BasicDBObject("username", username);
            BasicDBObject updateFields = new BasicDBObject();
            updateFields.append("fullnames", agent.getFullnames());
 BasicDBObject setQuery = new BasicDBObject();
            setQuery.append("$set", updateFields);
            getLiveagentCollection().update(searchQuery, setQuery);

The updated records shoould remain persisted on the DB 更新后的记录仍然存在于数据库中

I was able to resolve this issue, by adding writeconcern within the mongodb. 通过在mongodb中添加writeconcern,我能够解决这个问题。

MongoClient client = new MongoClient("localhost", 27112);
client.setWriteConcern(WriteConcern.MAJORITY);

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

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