Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
In the previous articles, we have covered the need for mongoose and how we should proceed with writing documents there. Now, in this article, we are concerned about how we can update them. Sounds interesting, right !!.
// Document is updated by setting the property, and calling save(). doc.title = 'Hello Coders'; await doc.save();
Different nuances are present for the above example. save() is a method present in the example. This implies you must be having some files to save. You need to use find() or get() to identify or search any document.
In the next steps, Mongoose knows how to change tracks. On calling doc.save() beneath the hood, Mongoose knows that you have already set the title, and it transforms your set call to the updateOne({ $set : { title } }).
Using Model.updateOne() and Model.updateMany()
In general, we know that we need to load the data from the database for any kind of update in the data. But using Model.updateOne() and Model.updateMany(), data can be updated with loading it from the database. Go through the below example:
// Loading the document to see the updated value const doc = await CharacterModel.findOne(); doc.title; // "Hello coders"
updateMany() plays quite a similar role. As the name suggests, updateOne() will update only one function at a time of the document, whereas, updateMany() will update every document that matches the filter and requirements.
Try to use save() as much as you can. Rather using updateOne() or updateMany().
The work in updateOne() is automatic. If a document is loaded using find(), we can change it before the save().
Using updateOne(), you don’t need to load the document into memory, this feature is very helpful especially for huge size files.
Using Document#updateOne()
The Document#updateOne() function is very helpful for Model.updateOne(). It provides syntactic sugar syrup to it. If the document is already present in memory, doc.updateOne() will be structuring a Model.updateOne() call.
In general, the Document#updateOne() is rarely used. Its preferred to use save() and Model.updateOne() for cases when save() is not flexible.
Using Model.findOneAndUpdate()
Model.findByIdAndUpdate() is another variation of Model.findOneAndUpdate() function. Both these functions behave similarly to the updateOne() function. The first document gets automatically updated when the first parameter matches. But in updateOne(), it returns back the updated document.
const doc = await CharacterModel.findOneAndUpdate( { name: 'James Gill' }, { title: 'Helllo Coders' }, // If `new` isn't true, `findOneAndUpdate()` will return the // document as it was _before_ it was updated. { new: true } );
doc.title; // "Hello coders"
Quick precap
Atomic
Doc in memory
Returns updated doc
Change tracking
Document#save()
❌
✅
✅
✅
Model.updateOne()
✅
❌
❌
❌
Model.updateMany()
❌
❌
❌
❌
Document#updateOne()
❌
✅
❌
❌
Model.findOneAndUpdate()
✅
❌
✅
❌
FAQs
Define a schema? In Mongoose, the schema refers to the representation of a particular document, either partially or completely. In other ways, the way of expressing indexes, properties, values as well as constraints is known as schema.
Which is better to use MongoDB or mongoose? As such there is no benefit, both have their advantages based on different applications it is used for. For multi-tenant applications, MongoDB native driver is a good choice. Whereas mongoose as an ORM(Object Relational Mapping) is a better option for newbies.
Mention the use of findOneAndDelete()? This function is preferred for finding out the matching documents, removing it, and then returning the modified document to the callback.
What value is returned by findOneAndDelete()? This function returns the modified document after the deletion has been performed(as a requirement).
Key Takeaways:
This article covers various ways we can update various documents in Mongoose. It starts its discussion with the need for an update, then moves towards save(), Model.updateOne(), and many functions. At last, we have gone through the quick recap of the whole.
Keeping the theoretical knowledge at our fingertips helps us get about half the work done. To gain complete understanding, practice is a must. To achieve thorough knowledge, visit our page.
Live masterclass
Zomato Data Analysis Case Study: Ace 25L+ Roles in FoodTech
by Abhishek Soni
16 Mar, 2026
01:30 PM
Data Analysis for 20L+ CTC@Flipkart: End-Season Sales dataset
by Sumit Shukla
15 Mar, 2026
06:30 AM
Beginner to GenAI Engineer Roadmap for 30L+ CTC at Amazon
by Shantanu Shubham
15 Mar, 2026
08:30 AM
Multi-Agent AI Systems: Live Workshop for 25L+ CTC at Google
by Saurav Prateek
16 Mar, 2026
03:00 PM
Zomato Data Analysis Case Study: Ace 25L+ Roles in FoodTech
by Abhishek Soni
16 Mar, 2026
01:30 PM
Data Analysis for 20L+ CTC@Flipkart: End-Season Sales dataset