【发布时间】:2021-12-20 01:06:33
【问题描述】:
这个问题与其他类似问题不同,因为 { upsert: true } 选项没有提供所需的输出。 我想更新/插入以下文档:
{
_id: {
playerId: '1407081',
tournamentId: '197831',
matchId: '1602732'
},
playerName: 'abcd',
points: -5
}
执行下面给出的代码后,
await Points.findOneAndUpdate(
{
"_id": playerStatsObjForDB._id
},
{
playerStatsObjForDB
},
{
upsert: true
}
);
//where playerStasObjForDB is same as object mentioned in top.
如果文档不存在,则插入以下文档:
{
"_id": {
"playerId":"1407081",
"tournamentId":"197831",
"matchId":"1602732"
},
"__v":0,
}
我正在使用猫鼬,但非常感谢任何帮助。
【问题讨论】:
标签: node.js mongodb mongoose mongodb-query