栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在MongoDB中正确进行批量更新/更新

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在MongoDB中正确进行批量更新/更新

您的语法在这里基本上是正确的,但是您的常规执行是错误的,因此您应该将“ 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驱动程序。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/427136.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号