我正在使用“migrate-mongo”:“^10.0.0”包。
不知何故 updateOne 不起作用:
module.exports = {
async up(db, client) {
db.collection("users").updateOne(
{ _id: "63918aa70e345d3c60b740c3" },
{ $set: { promotedAt: 1234567890 } }
);
},
async down(db, client) {
db.collection("users").updateOne(
{ _id: "63918aa70e345d3c60b740c3" },
{ $set: { promotedAt: null } }
);
},
};
我做错了什么?
ChatGPT 没用:((
updateMany 方法工作正常
假设“不起作用”意味着不返回错误但也不更新文档,这很可能是类型不匹配。
"63918aa70e345d3c60b740c3"
是一个字符串,而_id字段的默认类型是ObjectId。
由于 MQL 运算符对类型敏感,因此您需要对其进行转换,以便查询匹配,可能使用类似
ObjectId("63918aa70e345d3c60b740c3")
的内容。