node.jsでMongoDBを使用しています
私が望むのは、コレクション内のドキュメントをアップサートすることです。ドキュメントには、一意の ID、最後にアクセスされた日付を格納する lastAccess フィールド、およびドキュメントの作成時に 0 に設定され、更新時に 1 ずつ増加する timesAccessed フィールドがあります。
私は試した:
// coll is a valid collection
coll.update(
{user: accountInfo.uid},
{user: accountInfo.uid,
lastAccess: new Date(),
$inc: {timesAccessed: 1},
$setOnInsert: {timesAccessed: 0}
},
{upsert: true, w: 1},
function(err, result) {
if (err) throw err;
console.log("Record upserted as " + result);
});
しかしノードは言う:
MongoError: Modifiers and non-modifiers cannot be mixed
これを行うための正確で安全な方法は何ですか?