5
我正在學習node.js和mongodb。我在我的應用程序中使用mongoskin模塊,但似乎無法獲得「upsert」功能。Mongsert的Upsert(node.js和mongodb)
我讀過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.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);
如何創建「更新或插入,如果不存在」的功能?