如何通过shell更改MongoDB中的writeConcern?

时间:2015-10-30 10:13:38

标签: mongodb

我可以通过JAVA客户端更改默认写入问题,即ACKNOWLEDGE。

但是,如何在通过shell插入文档时更改MongoDB中的writeConcern?有可能吗?

1 个答案:

答案 0 :(得分:3)

更新操作可以接受writeConcern文档。

插入示例:

db.collection.insert(
    { x : 1 },
    { writeConcern: { w: 2 } }
)

更新示例:

db.collection.update(
    { x : 1 },
    { $set : { y : 2 } },
    { upsert: true, writeConcern: { w:1, j:true } }
)

删除示例:

db.collection.remove(
    { x : 1 },
    { writeConcern: { wtimeout: 5000 } }
)