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

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?