如何更新 MongoDB 中的布尔值

How to update boolean in MongoDB

我有一个 boolean 需要在 mongoDB 中更新,具体取决于 user/restaurant 是否处于活动状态。有什么办法吗?这是我目前所拥有的

架构 - 简化

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

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

控制器:

  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));
 },