The mongoose.model() function of the mongoose module is used to create a collection of a particular database of MongoDB. The name of the collection created by the model function is always in plural format mean GFG to gfss and the created collection imposed a definite structure.
Parameters: This function accepts the following two parameters:
- Collection name: It is the name of the collection.
- Collection Schema: It is the schema of the collection.
Return type: This function returns the Mongoose object.
Installing Module: Install the mongoose module using the following command:
npm install mongoose
Project Structure: Our project structure will look like this:
Running the server on Local IP: Data is the directory where MongoDB server is present.
mongod --dbpath=data --bind_ip 127.0.0.1
Run index.js file using below command:
MongoDB Database: Our database after executing the above command will look like this:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.