2012-04-28 18 views
5

मैं node.js और mongodb सीख रहा हूँ। मैं अपने ऐप में mongoskin मॉड्यूल का उपयोग कर रहा हूं, लेकिन मुझे काम करने के लिए "अपरर्ट" कार्यक्षमता नहीं मिल रही है।Mongoskin (node.js और mongodb) के साथ उपज

मैंने जिथब पर (बल्कि अपारदर्शी) 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); 

मैं "अद्यतन या सम्मिलित नहीं तो मौजूद है" कैसे बना सकता हूँ कार्यक्षमता कर सकते हैं?

उत्तर

9

मैं इसे करने की कोशिश नहीं की है, लेकिन इस दस्तावेज़ यहां के अनुसार: https://github.com/guileen/node-mongoskin#inherit-updating और यहाँ: https://github.com/christkv/node-mongodb-native/blob/master/docs/insert.md, ऐसा लगता है options की तरह तीसरे पैरामीटर है, और यह एक वस्तु है, इसलिए की तरह बनना चाहिए था:

db.collection("stuff").update({b:"B"}, {y:"YY"}, {upsert:true}); 
संबंधित मुद्दे