Take it easy with Mongoskin (node.js and mongodb)

I am learning node.js and mongodb. I use the mongoskin module in my application, but I can not get upsert to work.

I read the (rather opaque) mongoskin github guide. Here is what I have tried so far:

// this works.  there 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);

How can I create the update or paste if none exists functionality?

+5
source share
1 answer

I have not tried, but according to the document, https://github.com/guileen/node-mongoskin#inherit-updating and here: https://github.com/christkv/node-mongodb-native/blob/master/docs /insert.md seems to optionsbe the third parameter, and it should be an object, for example:

db.collection("stuff").update({b:"B"}, {y:"YY"}, {upsert:true});
+9
source