gpt4 book ai didi

javascript - 如何在 MongoDB 中更新 boolean 值

转载 作者:行者123 更新时间:2023-11-30 20:24:00 28 4
gpt4 key购买 nike

我有一个 boolean 需要根据用户/餐厅是否活跃在 mongoDB 中更新。有什么办法吗?这是我目前所拥有的

架构 - 简化

const ownerSchema = new Schema({
name: { type: String, required: true },
foodType: { type: String, required: true },
location: { type: Array, default: [] },

active: { type: Boolean, default: false },
});

和 Controller :

  isActive: function(req, res) {
console.log(req.body);
db.Owners.updateOne({ _id: req.params.id })
.then(dbModel => res.json(dbModel))
.catch(err => res.status(422).json(err));
},

我只需要一种简单的方法来将其更改为 true 和 false。任何帮助将不胜感激!

最佳答案

尝试

db.Owners.update({ _id: req.params.id },{"$set":{"active":false}})
.then(dbModel => res.json(dbModel))
.catch(err => res.status(422).json(err));
},

关于javascript - 如何在 MongoDB 中更新 boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51120104/

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