duangu1868 2014-09-22 22:54
浏览 327
已采纳

MongoDB :: setWriteConcern默认值?

I have a specific question with the way the PHP Mongo driver handles figuring out setWriteConcern and setReadPreferences. From the documentation I gather that:

  1. You can change writeConcern at the individual insert, update, remove level.
  2. You can adjust the writeConcern at the connection level.
  3. You can use MongoCollection::setWriteConcern to set the default for this collection.
  4. You can use MongoDB::setWriteConcern to set the default for this database.

We are testing a sharded, replicated setup and I am wondering if I use MongoDB::setWriteConcern and later do an insert on a collection in that database without specifying any write concern will it default to the concern I did on the DB object itself?

Basically, if I set a default writeConcern, or readPreference for that matter, on a DB/Collection does that info get synced to the config servers such that all subsequent connections will default to those concerns/preferences if none are specified at the connection or query level?

  • 写回答

1条回答 默认 最新

  • doudeng5218 2014-09-23 03:05
    关注

    If you use setWriteConcern to set the default, it will affect only the subsequent write operations within the mongo client/shell you are using.

    For example, open a mongo shell and type this:

    db.setWriteConcern(1)
    

    Now check the default in the same shell:

    db.getWriteConcern()
    WriteConcern({ "w" : 1 })
    

    Then open another mongo shell and getWriteConcern, you should see null value.

    db.getWriteConcern()
    null
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度