duanniu3385 2015-05-06 19:40
浏览 21

覆盖Labix mgo中的默认writeConcern

I'm using labix mgo as a mongodb driver in my Go app and I'm wondering if there is a way to override the default writeConcern for specific queries.

A few words about configuration: the replica set has three nodes - one primary and two secondaries, the writeConcern and readPreference are default. The driver uses monotonic consistency which means that all reads are done from the secondary (when it's available, otherwise - from the primary).

There might be cases when I need to read the updated data right after writing to the database - and because of the above mongo might return the old data:

// update some data
_ := collection.Update(bson.M{"_id": "some_id"}, bson.M{"key": "value"})

// the data is still not updated when I read it immediately after update
var obj interface{}
_ := collection.Find(bson.M{"_id": "some_id"}).One(&obj)

The question is: is it possible to override the default writeConcern (or default consistency of the driver) and force the driver to wait until the data is written to the secondaries OR to read from the primary for some of the queries?

Appreciate any suggestions.

  • 写回答



      相关推荐 更多相似问题


      • ¥15 和您碰到了同一个问题
      • ¥15 如何在微信支付V3PHP版请求中添加header?
      • ¥15 在数字信号处理中用MATLAB显示波形。
      • ¥15 keil MDK软件进行仿真调试的局限
      • ¥15 关于gateway产生临时文件夹的问题
      • ¥15 Java Broken Pipe以及OOM
      • ¥20 请问有没有RTL8211FS的参考原理图
      • ¥50 esp32的platfromio工程添加文件就会编译失败
      • ¥15 linux下运行VASP报错
      • ¥15 python里面查找赋值,如何可以在剩余未空值的行里面进行进一步的筛选呢?