IT engineer, I like to Learn and Build.
- 🌱 Always
learning
- 🤝 I’m looking forward to collaborating with other developers and learning from them.
- 📪 How to reach me:
bhavinvirani45@gmail.com
Posted on June 15, 2021
MnongoDB provides it's native driver to work with our project at server side but it may be large amount of code or repetition in code but it's not the case with mongooses. In this article I am going to tell you how to get started with mongoose
Mongoose is a Node.js package that gives you an interface to play with mongo database. It is very light weight npm
package to use in our application. Mongoose has all sets of methods that help you to connect and access data stored in Mongo database.
Mongoose is an Object Data Modeling (ODM)
library for MongoDB and Node.js. Mongoose.js provides an abstraction layer on top of MongoDB that eliminates the need to use named collections in native MongoDB driver. Mongoose makes MongoDB easier to work
with MongoDB. Mongoose allow developers to enforce a specific schema of desired object at the application layer.
1. Installing and Requiring Mongoose
2. Connecting To MongoDB database
3. Defining Schema
4. Creating Model
5. Creating and Saving Instance
6. Reading from DB
7. Updating
8. Deleting
npm install mongoose --save
Syntex
mongoose.connect(<Database URI>);
Using connection URI of database we cane connect to database.
here test is Database name
You can get connection Instance by const db = mongoose.connect;
db object is used to listen the events attached to it.
We can use any function method. so don't get confused😕 by seeing it.
collection name
and schema name
.save()
method on model.
find()
on model and also find document by it's id using findById()
Github 👁
Posted on June 15, 2021
Sign up to receive the latest update from our blog.