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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里