gpt4 book ai didi

javascript - 获取 Mongoose UpdateMany 受影响文档的数量

转载 作者:行者123 更新时间:2023-12-01 00:00:24 25 4
gpt4 key购买 nike

假设我们有代码:

 await Employees.updateMany(
{
InsertDate: {
$gte: _yesterday, // date ojbect that is passed as a param
$lte: _today // date ojbect that is passed as a param
}
},
{ $set: { RegistrationDate: ... // some var that I generate } }
);

我们如何获得受影响文档的数量(计数)?

最佳答案

docs 中所述,您可以在响应的 nModified 字段中获取更新文档的数量。

所以你可以像这样访问它:

const response = await Employees.updateMany(
{
InsertDate: {
$gte: _yesterday, // date ojbect that is passed as a param
$lte: _today // date ojbect that is passed as a param
}
},
{ $set: { RegistrationDate: ... // some var that I generate } }
);

console.log("Number of updated documents: ", response.nModified);

关于javascript - 获取 Mongoose UpdateMany 受影响文档的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60775000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com