Toggle a boolean value with mongoDB

If you are using MongoDB 4.2, you can use aggregation operators in your update statement, like:

.findOneAndUpdate({_id: day.id},[{$set:{present:{$eq:[false,"$present"]}}}]);

That will set present to true if it is false, and to false if it is any other value.

Leave a Comment