【发布时间】:2019-05-02 10:13:41
【问题描述】:
这是我的代码:
const result = await Todo.updateMany(
{ _id: { $in: ids }, userId },
{ $set: { complete } },
{ new: true }
).populate('userId', '_id');
res.json({ todos: result })
它适用于更新数据,但它返回:
{ n: 1,
nModified: 1,
opTime:
{ ts:
Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1543568180 },
t: 1 },
electionId: 7fffffff0000000000000001,
ok: 1,
operationTime:
Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1543568180 },
'$clusterTime':
{ clusterTime:
Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1543568180 },
signature: { hash: [Binary], keyId: [Long] } } }
如何退回更新后的模型?
【问题讨论】:
-
updateMany操作没有new: true选项,甚至不返回更新后的文档。如果您需要获取更新的文档,您需要使用update或findOneandUpdate命令在ids上进行映射。