5

私はnode.jsとmongodbを学んでいます。アプリでmongoskinモジュールを使用していますが、「アップサート」機能を動作させることができないようです。

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);

「存在しない場合は更新または挿入」機能を作成するにはどうすればよいですか?

4

1 に答える 1

9

私はそれを試していませんが、ここのドキュメントによると: https://github.com/guileen/node-mongoskin#inherit-updatingそしてここ:https : //github.com/christkv/node-mongodb-native/ blob / master / docs / insert.mdは、3番目のパラメーターのように見え、次optionsのようにオブジェクトであると想定されています。

db.collection("stuff").update({b:"B"}, {y:"YY"}, {upsert:true});
于 2012-04-28T21:00:55.460 に答える