Javascript mongodb找不到匹配项
我是mongodb的新手。上面是api中用于更新某些数据的函数。 Enroll的架构如下所示:Javascript mongodb找不到匹配项,javascript,mongodb,Javascript,Mongodb,我是mongodb的新手。上面是api中用于更新某些数据的函数。 Enroll的架构如下所示: Enroll.updateOne( { "reviewers._id": userID, }, { $set: { "reviewers.$.scores": req.body.scores, }, }, (errUpdate, re
Enroll.updateOne(
{
"reviewers._id": userID,
},
{
$set: {
"reviewers.$.scores": req.body.scores,
},
},
(errUpdate, resultUpdate) => {
if (errUpdate) {
return res.status(500).json({ success: false, error: errUpdate });
} else {
return res.status(200).json({ success: true, data: resultUpdate });
}
}
);
但是当我调用api时,它返回n:0,这表示找不到匹配项。我是否遗漏了一些步骤?您能否打印
userID
,并确保类型与数据库中存储的值匹配?(string vs ObjectId)我已经通过const userID=mongoose.Types.ObjectId(req.body.userID)将userID转换为mongo对象id;
[
{
_id: xxxxx,
otherdata: xxxx,
reviewers: [ { _id: xxxx, otherdata: xxxx } , { _id: xxxx2, otherdata: xxxx2 } ]
},
{
second enroll item...
}
]