Im trying to figure out how to toggle the boolean value of "active" in the example from true to false or false to true based on the value existing in the document. So if its true, change it to false and if its false, change it to true. Example array.
[{ _id: 59cb78434436be173e038aaa, active: true, title: 'One' },
{ _id: 59cb78434436be173e038aab, active: false, title: 'Two' },
{ _id: 59cb78434436be173e038aac, active: false, title: 'Three' }]
const todos = db.collection('todos');
const active = !active;
await todos.findOneAndUpdate({ _id: ObjectID(args.id) },
{ $set: { active: active } }, function(err, doc) {
if (err) {
throw err;
} else {
console.log('Updated');
}
});
I cant set this directly by passing true or false to active { $set: { active: true }}
. How would I test the value and return the opposite?
Thanks