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 badges1 Answer
Reset to default 4Try
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
版权声明:本文标题:javascript - How to update boolean in MongoDB - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744204021a2595097.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论