28
Connecting to MongoDB with Mongoose
During the starting days of my journey into back-end programming, I had taken too much information right in the beginning. Although it's good to have plenty of resources but at times too much information right in the beginning this can be overwhelming !
Especially while connecting my app to mongoDB, I used to look out for pieces that would give me an overview of how it all inter connected behind the scenes. I did find some amazing pieces on many websites, but not exactly how I wanted it, hence after finally learning it I decided to write my own.
Enough with the small talks, Let's express our way into mongoDB on a mongoose !



















mongoose.connect('<your-URI-here>', {useNewUrlParser: true, useUnifiedTopology: true}).then(()=>console.log("connected !!")).catch(error=>console.error("mongoose connection failed...", error))

You are now connected to your mongoDB Atlas database using mongoose from your node app !
You can refer to the following repl for the exact code :
https://replit.com/@ShasheeshPuroh1/mongoDB#index.js
https://replit.com/@ShasheeshPuroh1/mongoDB#index.js
28