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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 咨询一下有关于王者荣耀赢藏战绩
  • ¥100 求购一套带接口实现实习自动签到打卡
  • ¥50 MacOS 使用虚拟机安装k8s
  • ¥500 亚马逊 COOKIE我如何才能实现 登录一个亚马逊账户 下发新 COOKIE ..我使用下发新COOKIE 导入ADS 指纹浏览器登录,我把账户密码 修改过后,原来下发新COOKIE 不会失效的方式
  • ¥20 玩游戏gpu和cpu利用率特别低,玩游戏卡顿
  • ¥25 oracle中的正则匹配
  • ¥15 关于#vscode#的问题:把软件卸载不会再出现蓝屏
  • ¥15 vimplus出现的错误
  • ¥15 usb无线网卡转typec口
  • ¥30 怎么使用AVL fire ESE软件自带的优化模式来优化设计Soot和NOx?