04 - Create Many Records with model.create() - MongoDB and Mongoose - freeCodeCamp Tutorial
Ganesh H
We can bulk create many records in our database. Firstly, we set up an array with objects containing properties and values that correspond with our model's schema, and then call the create() method on the model with the array. This will generate documents from each object in the array and write them to the database.
Link to challenge : https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/create-many-records-with-model-create Written Guide : https://www.notion.so/ganeshh123/Create-Many-Records-with-model-create-8979434395c34ee0bdc194253de85f7d
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: model.create() Shortcut for saving one or more documents to the database. MyModel.create(docs) does new MyModel(doc).save() for every doc in docs. https://mongoosejs.com/docs/api/model.html#model_Model.create
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 representation of those objects in MongoDB.
freeCodeCamp (also referred to as “Free Code Camp”) is a non-profit organization that consists of an interactive learning web platform, an online community forum, chat rooms, online publications ... https://www.youtube.com/watch?v=6AMUMuiWpGY
17853179 Bytes