admin管理员组

文章数量:1398984

I have a boolean that I need to update in mongoDB depending on if the user/restaurant is active or not. Is there any way to do this? this is what I have so far

The Schema - simplified

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

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

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

I just need an easy way to change it to true and false. Any help would be appreciated!

I have a boolean that I need to update in mongoDB depending on if the user/restaurant is active or not. Is there any way to do this? this is what I have so far

The Schema - simplified

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

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

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

I just need an easy way to change it to true and false. Any help would be appreciated!

Share Improve this question edited Jul 1, 2018 at 3:14 Sajeetharan 223k65 gold badges366 silver badges408 bronze badges asked Jul 1, 2018 at 3:05 Ariel SolanoAriel Solano 1813 gold badges3 silver badges7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Try

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

本文标签: javascriptHow to update boolean in MongoDBStack Overflow