08 - Perform Classic Updates Running Find, Edit, Save - MongoDB and Mongoose - freeCodeCamp Tutorial
Ganesh H
To Update records, it's a 3 step process: Find and Retrieve the record, Edit and make changes, and Save the changes to the database. We can combine the concepts we learned in the previous challenges to do this.
Link to challenge : https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/perform-classic-updates-by-running-find-edit-then-save Written Guide : https://www.notion.so/ganeshh123/Perform-Classic-Updates-by-Running-Find-Edit-then-Save-11a8663dc65145fabbe022a893510910
Full Playlist for this course : https://www.youtube.com/playlist?list=PLhGp6N0DI_1QJMb63oecYZ3lLjrF4PnIs All Writen Guides for this course : https://www.notion.so/ganeshh123/6f987e7260914612b06adf840dbb00c3 All My Tutorials can be found at : https://www.notion.so/Tutorials-Ganesh-H-293ea420d34a464f9a1907e0405b5f26
Concepts: findById() Finds a single document by its _id field. findById(id) is almost* equivalent to findOne({ _id: id }). If you want to query by a document's _id, use findById() instead of findOne(). https://mongoosejs.com/docs/api.html#model_Model.findById
model.findOne() Behaves like .find(), but it returns only one document (not an array), even if there are multiple items. It is especially useful when searching by properties that you have declared as unique. https://mongoosejs.com/docs/api.html#model_Model.find
document.save() Saves this document by inserting a new document into the database if document.isNew is true, or sends an updateOne operation only with the modifications to the database, it does not replace the whole document in the latter case. https://mongoosejs.com/docs/api/document.html#document_Document-save
Model Models are fancy constructors compiled from Schema definitions. An instance of a model is called a document. Models are responsible for creating and reading documents from the underlying MongoDB database. https://mongoosejs.com/docs/models.html
mongoose.model() When you call mongoose.model() on a schema, Mongoose compiles a model for you. The first argument is the singular name of the collection your model is for. Mongoose automatically looks for the plural, lowercased version of your model name. https://mongoosejs.com/docs/models.html#compiling
-————————————————————————————————————- MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL).
Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js. It manages relationships between data, provides schema validation, and is used to translate between objects in code and the representat ... https://www.youtube.com/watch?v=e_sxDMDmSo4
23865974 Bytes