向上插入Mongoskin(node.js和mongodb)
我正在学习node.js和mongodb。我正在我的应用程序中使用mongoskin模块,但我似乎无法让“upsert”功能正常工作 我已经阅读了github上的(相当不透明的)mongoskin指南。以下是我迄今为止所尝试的:向上插入Mongoskin(node.js和mongodb),node.js,mongodb,upsert,Node.js,Mongodb,Upsert,我正在学习node.js和mongodb。我正在我的应用程序中使用mongoskin模块,但我似乎无法让“upsert”功能正常工作 我已经阅读了github上的(相当不透明的)mongoskin指南。以下是我迄今为止所尝试的: // this works. there's an insert then an update. The final "x" is "XX". db.collection("stuff").insert({a:"A"}, {x:"X"}); db.collectio
// this works. there's an insert then an update. The final "x" is "XX".
db.collection("stuff").insert({a:"A"}, {x:"X"});
db.collection("stuff").update({a:"A"}, {x:"XX"});
// this does NOT work. I thought it would do an upsert, but nothing.
db.collection("stuff").update({b:"B"}, {y:"YY"}, true);
如何创建“不存在时更新或插入”功能?我没有尝试过,但根据这里的文档:,它看起来像是第三个参数,应该是一个对象,如下所示:
db.collection("stuff").update({b:"B"}, {y:"YY"}, {upsert:true});