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.
More Related Contents:
- Fastest way to remove duplicate documents in mongodb
- How to remove duplicates based on a key in Mongodb?
- How does MongoDB sort records when no sort order is specified?
- How to listen for changes to a MongoDB collection?
- Cascade style delete in Mongoose
- Find MongoDB records where array field is not empty
- MongoDB – Update an object in nested Array
- Creating Multifield Indexes in Mongoose / MongoDB
- Mongodb Explain for Aggregation framework
- MongoDB aggregation comparison: group(), $group and MapReduce
- Multiple Counts with single query in mongodb
- NoSQL (MongoDB) vs Lucene (or Solr) as your database [closed]
- Delete everything in a MongoDB database
- Failed to start mongod.service: Unit mongod.service not found
- How to return array of string with mongodb aggregation
- Mongoose’s find method with $or condition does not work properly
- return query based on date
- MongoParseError: options useCreateIndex, useFindAndModify are not supported
- Can’t find documents searching by ObjectId using Mongoose
- Mongodb aggregation $group, restrict length of array
- mongodb – Find document with closest integer value
- mongodb, replicates and error: { “$err” : “not master and slaveOk=false”, “code” : 13435 }
- MongoDB/NoSQL: Keeping Document Change History
- Update a value in MongoDB based on its current value
- Meteor: uploading file from client to Mongo collection vs file system vs GridFS
- MongoDB $lookup on nested document
- How are MongoDB’s ObjectIds generated?
- How to get all result if unwind field does not exist in mongodb
- Get a document in MongoDB without specifying collection
- How to create a Mongo Docker Image with default collections and data?