您的语法在这里基本上是正确的,但是您的常规执行是错误的,因此您应该将“ upsert”操作与其他修改“分开”。否则,这些将“冲突”并在发生“
upsert”时产生错误:
LineupPointsRecord.native(function (err,collection) { var bulk = collection.initializeOrderedBulkOp(); // Match and update only. Do not attempt upsert bulk.find({ "teamId": lineUpPointsGeneralRecord.teamId, "round": 0 }).updateOne({ "$inc": { "lfPoints": roundPoints }, "$push": { "roundPoints": roundPoints } }); // Attempt upsert with $setonInsert only bulk.find({ "teamId": lineUpPointsGeneralRecord.teamId, "round": 0 }).upsert().updateOne({ "$setOnInsert": lineUpPointsGeneralRecord }); bulk.execute(function (err,updateResult) { sails.log.debug(err,updateResult); });});确保您的sails-mongo是正确支持Bulk操作的最新版本,并包含最新的节点本机驱动程序。最新的版本支持v2驱动程序。



