duangu1868
2014-09-22 22:54
浏览 176

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?

图片转代码服务由CSDN问答提供 功能建议

我对PHP Mongo驱动程序处理setWriteConcern和setReadPreferences的方式有一个特定的问题。 从我收集的文档:

  1. 您可以在单独的插入,更新,删除级别更改writeConcern。
  2. 您可以调整 连接级别的writeConcern。
  3. 您可以使用MongoCollection :: setWriteConcern设置此集合的默认值。
  4. 您可以使用MongoDB :: setWriteConcern设置默认值 对于这个数据库。

    我们正在测试一个分片的,复制的设置,我想知道我是否使用MongoDB :: setWriteConcern,然后在一个集合中插入 没有指定任何写入问题的数据库是否会默认我对DB对象本身的关注?

    基本上,如果我在DB /上设置了默认的writeConcern或readPreference 集合是否会将这些信息同步到配置服务器,以便所有后续连接都默认为那些关注/首选项(如果在连接或查询级别没有指定)?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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
    
    点赞 评论

相关推荐 更多相似问题