gpt4 book ai didi

node.js - 如何将 Mongoose 中的 bool 字段更新为相反的字段?

转载 作者:行者123 更新时间:2023-12-02 02:14:13 26 4
gpt4 key购买 nike

所以我有这个功能:

async function update_subscription_status(id) {
await User.updateOne({chat_id: id}, {
mailing: // need to change this boolean field to its opposite
})
}

有什么方法可以在更新之前不检查其状态吗?

最佳答案

使用update-documents-with-aggregation-pipeline

$set

$eq返回 true 或 false

async function update_subscription_status(id) {
await User.updateOne(
{ chat_id: id },
[ { "$set": { "mailing": { "$eq": [false, "$mailing"] } } } ]
)
}

关于node.js - 如何将 Mongoose 中的 bool 字段更新为相反的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67361357/

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