w, {Number/String, > -1 || ‘majority’ || tag name} the write concern for the operation where < 1 is no acknowlegement of write and w >= 1, w = ‘majority’ or tag acknowledges the write 基本上所有的函数里的w都这么描述,但是这个真的看不懂。
求解释。
另外这个参数跟safe:ture/false有关系吗?
5 回复
safe:ture/false以及被淘汰了,这是过去的参数,现在用w表示,w=0相当于saft=false的形式,当然w能够表达的存储方式已经超越了saft=true,w=1表示只有一个节点写入成功即返回,w=2表示两个节点写入成功才返回,更多w的含义请查看官方文档.一般w=1就可以了
w参数是write concern 看官网描述
write concern Specifies whether a write operation has succeeded. Write concern allows your application to detect insertion errors or unavailable mongod instances. For replica sets, you can configure write concern to confirm replication to a specified number of members.