[英]Mongoose `findById` not returning expected document
當我使用以下行找到文檔時:
const user = await User.findById(req.user.id).populate('input')
然后我 console.log user
,我可以看到滿足查詢的文檔。
但是,當我添加.updateOne({ formResponded: '1' });
到上一行,如下所示:
const user = await User.findById(req.user.id).populate('input').updateOne({ formResponded: '1'});
而我 console.log user
我沒有得到任何記錄,而是一個看起來像這樣的對象:
{ n: 1,
nModified: 1,
opTime: {
ts: Timestamp { _bsontype: 'Timestamp', low_: 2, high_: 1635212112 },
t: 41
},
electionId: 7fffffff0000000000000029,
ok: 1,
'$clusterTime': {
clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 2, high_: 1635212112 },
signature: { hash: [Binary], keyId: [Long] }
},
operationTime: Timestamp { _bsontype: 'Timestamp', low_: 2, high_: 1635212112 }
}
為什么會發生這種情況?
固定的:
const user = await User.findByIdAndUpdate({ _id: req.user.id }, { formResponded: '1' }).populate('input')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.