求问node-mongodb-native里,那个w参数是什么意思?
发布于 11 年前 作者 yusk013 6070 次浏览 最后一次编辑是 8 年前

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 回复

当你遇到要用这个就明白了

我原来一直用mongoskin,但是最近发现他有问题,就去看原生的驱动。但是发现这里有这样一个参数,但是始终看不明白。 有朋友给解释一下吗?

safe:ture/false以及被淘汰了,这是过去的参数,现在用w表示,w=0相当于saft=false的形式,当然w能够表达的存储方式已经超越了saft=true,w=1表示只有一个节点写入成功即返回,w=2表示两个节点写入成功才返回,更多w的含义请查看官方文档.一般w=1就可以了

友情提示一下w是write的简写形式哈哈

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.

回到顶部