如果upsert是declare,为什么用大块y替换其他字段?
我做错了什么?
原创集合:
{
_id:'xx',
a:1
}流程
var bulk = collection.initializeUnorderedBulkOp();
users.forEach(x => {
bulk
.find({ _id:'xx'})
.upsert()
.updateOne({
b: 2
});
});
bulk.execute();结果
{
_id:'xx',
b:2
}发布于 2019-04-05 09:11:50
现在我明白了!我需要使用$set命令,以便它只更新一些字段。
var bulk = collection.initializeUnorderedBulkOp();
users.forEach(x => {
bulk
.find({ _id:'xx'})
.upsert()
.updateOne({
$set: //CHANGED LINE
{
b: 2
}
});
});
bulk.execute();现在它可以工作了
{
_id:'xx',
a:1,
b:2
}https://stackoverflow.com/questions/55526829
复制相似问题