Connecting NodeJS with MongoDB | Mongoose + Express
Вставка
- Опубліковано 10 лют 2025
- Hey Everyone, In this video, we are going to connect our Node application to MongoDB using mongoose.
Download MongoDB: www.mongodb.co...
► Complete Full Stack Web Developer RoadMap 2023: • Complete Full Stack We...
► Master NodeJS Playlist: • Master NodeJS
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows developers to run JavaScript on the server side, creating server-side applications with JavaScript.
► My Website: www.piyushgarg...
My Gears
► My Girlfriend: amzn.to/3WD6FRp
► Apple MacBook Laptop: amzn.to/3WBJgQn
► Anker USB Hub: amzn.to/3GhZSr0
► Blue Yeti Microphone: amzn.to/3YKZ9FT
► External 27” Monitor: amzn.to/3Vp3xaO
► Logitech MK295 Wireless Keyboard and Mouse: amzn.to/3DuL1bB
► Seagate Expansion 1TB External HDD: amzn.to/3QMm5Q8
► Tripod: amzn.to/3S4OwK4
► Ring Light: amzn.to/3YLf8DR
Disclaimer: All the links above are affiliate links.
Social Links
► Twitter - / piyushgarg_dev
► LinkedIn - / piyushgarg195
Video Titles
What is MongoDB?
How to Install MongoDB?
Getting Started with MongoDB
Mongoose and MongoDB
How to connect nodejs to MongoDB
what is mongoose
Tags
#nodejs #javascript #expressjs #mongodb #mernstack #developer #api #https #server #javascriptinhindi #webdevelopment #webapp #realtimeapp #serverside #nonblockingio #tech
I'm damn Sure that Nobody can beat this guy in UA-cam, Because He didn't speak a single line apart from the concept, all the 19 minutes and 17 seconds he invested in telling the concepts, I loved that,
And
Apart from that his explanation was next level, I understood every single thing.
Any new viewer of this channel can obviously go ahead and follow all of his playlist
Please try to make/create separate code for each ep if possible. Bcz it is difficult to connect to your video in-btn. Means I'm watching this vdo directly of your series and it is difficult to connect with your explanation bcz you are doing changes in your code which is written in previous videos.
No doubt Ur explanation is very good and I'm very excited to learn from U.
Instead, right now you can create copy of previous videos:)
u kn what i have watched 2 series from 2 courses like watched some initial videos but they made it so much complicated from the initial itself but sir u keep it really simple and much understandable
thank god i found this channel else i would be still searching for backend series and wasting my time
thank u so much piyush❤ keeping growing!
Best NodeJS series on the UA-cam.
Huge Respect Man ❤
I have been following this tutorial from beginning. I love learning and the way you teach that amazing. the way you speak slowly it helps digest each and every word. Thanks a lot :)
Literally, your method of teaching is so good and excellent. No doubt in saying that you are better than codewithharry and many others you tubers.
Hats off to your hard work and big fan of your teaching style :)
so much new things i am learning easily from these videos✨✨
schema is the blueprint(or structure) of collection->it is like class in oop
but model provide methords to actually intract with database->it it like object in oop as the instance of schema
Amazing analogy.. As I m from java
Man i love the way of your teaching. Paid course mein itna detail mein koyi nahi samjhaya ❤❤❤❤❤
Fantastic explanation! Your video breaks down complex concepts into easy-to-understand steps. The visuals and examples are spot on, making learning enjoyable and engaging. Keep up the great work-this is the kind of content that truly helps learners succeed!
Bohoti tagri explanation ha bhaiya maja a gaya 🔥🔥
Amazing series.. Sir you make everything so simple.. Thanks a lot🙏🙏
Thanks bro! I was stuck for too long due to a small mistake! You helped me resolve it.
Thanks you, with that video is easy learning mongo and node express
yes, ur tutorial solve my problems...thanks a lot boss
Great videos bhaiya ❤❤🔥🔥🔥🔥💪💪
Thanks Coding++
Best Series ever on backend.
appreciated 💯... sir
Also make tutorial on nodejs framework(nestJs).
God Level Explaining !!!!!!!!!!!!
excellent explanation
great way of explanation 🙏
nice explanation bhaiya
thanks a lot piyush sir great teacher and mentor
Thank you so much. You have explained very well!😊
Very nice explanation 👌
Nice Bro, very informative tutorial.
Bhaiya e series ke bad ReactJS ka advance topic bhi cover karwana like Data Handling, Reconciliation,Lazy Loading,Portals,Theming, Patterns,Anti-Patterns, Testing esab topic please cover karwaiyega.
Theek hai baccha - will cover
Thank you very much, keep them coming ❤
bro, you've been sent by God 🙏
😅
@@semicolon6499 ;
Isn't everyone sent by God lmao?
Bhai agar aapka full stack ho gya ho toh kuch tips doge ?? Mene js me project km bnaiye aur ye playlist follow kr raha hu.. koi dikkat toh ni hogi aapne jo difficulties face kri aur unko kaise handle kra bata sakte ho??
5:19 gender should be a enum but in 2024 I think String would be better 😂😂😂😂
thanks alot finally got it how it works
Sir will you upload a complete course of mern stack?
Yes 😄
great explanation
Which terminal should i open for mongosh , i am having problem to understand how to use it i able to Require mongoose , Make Schema , model but unable to understand which terminal is using for cmd like , show db ? Open MongoDB compass or CMD prompt ? How i get Mongos Power Shell i am using Windows.
direct type terminal in your dekstop search and you will get
Great explanation.
sir i am writing these code in the mt pc but here you have written
const result = await User.create({
})
but await is giving a error but you run successfully please explain
callback function ko aync kro
Hi Piyush please make a project based on this series
amazing 🔥
I am not able to install mongodb and mongosh on my ubuntu 22.10. I searched a lot but there were no mention of ubuntu 22.10 or 22.04lts on even offical docs.
So i am using atlas and compass.
Are you going to teach these ?
To install MongoDB on Ubuntu 22.10, you can follow these steps:
1. Import the MongoDB public GPG key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 4B7C549A058F8B6B
2. Create a list file for MongoDB:
echo "deb [ arch=amd64,arm64 ] repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
3. Reload the local package database:
sudo apt-get update
4. Install the MongoDB package:
sudo apt-get install -y mongodb-org
5. Start MongoDB:
sudo systemctl start mongod
6. Verify that MongoDB has started successfully:
sudo systemctl status mongod
7. Download the mongosh package from the MongoDB website.
curl -LJO github.com/mongodb/mongosh/releases/download/v1.0.0/mongosh-1.0.0-linux-x86_64.deb
8. Install the package using dpkg
sudo dpkg -i mongosh-1.0.0-linux-x86_64.deb
Then just run mongosh
@@piyushgargdev thank u, worked for me..
i dont know the concept of async and await where can i learn it from ?
pick up any yt ideo fo about 5-10 minutes that will be enough
Awesome 👍
Hey...Piyush will make some videos over "MongoDB aggregation pipeline" topic 😃😃😃😃👋👋👋👋
The best ❤❤
Great video 👍
Hi Piyush, we really appreciate the efforts you've put into creating these awesome tutorials. In this particular video, it would be helpful if you've also shared solution to two problems:
1) POST request with duplicate email crashes the server, how do we handle error here?
Since we've defined Mongoose schema with email: {required: true}, it throws an error and the server gets crashed if we put in the same/duplicate email id again -> as shown in your video as well. But what is the solution for this?
Also,
2) We are using MongoDB id creation value to find the database items. If we create our own custom id, ho do we fetch the data then? I am sure findById, findByIdandUpdate, findByIdandDelete methods won't work in this scenario. Using the Mongoose created ID is too long and not feasible to use.
use try and catch method it will handle the server crash case
same issue bro
@@vivekraiyani63 using Try and Catch method solved the problem
1st check for email if it already exists then throw and error message and if not then proceeds further
Add a middleware to check if the user already exists before proceeding to the insertion.
Awesome❤❤❤
Your explanation is good but the code looks so bad , use different code for each video so we can understand it better manner ..
Tare to karvu nahi.. bija kare aene to krvada. Bencbod
Bhai agar aapka full stack ho gya ho toh kuch tips doge ?? Mene js me project km bnaiye aur ye playlist follow kr raha hu.. koi dikkat toh ni hogi aapne jo difficulties face kri aur unko kaise handle kra bata sakte ho??
@@Deepak-gi8mp bhai js kr project jayda matter nahi krte 1-2 project bhi bahut hai and agar front-end complete ho gya hoto ek project react mai banao like accha portfolio and e-commerce website using redux toolkit or redux and agar aapka backend ho gya hoto uska project banao accha or agar backed sikhna hai to chai or code pr video dekh lo
Awesome video
hello bhaiya car rental app bna rha hu lakin mongodb nhi aata h but im trying to make a database but not able to do can you help please
hn bhai 4 mahine hogay... bangya?
Aur Bhai Fir 6 mahine hogay kuch bana kya?
this request takes too long to process it is timed out by the server in nodejs mongodb
Mai shared hosting use kar Raha hu jisme Nodejs 20.3.1 hai aur Maine apni Nodejs website ko version 21 par banaya hai... Kya ye MongoDB connection string ki problem hai...?? Ye kaun si problem hai aur kaise sahi Karu... Please guide me ..
Guide me
Thanks a lot man.. I was using this but putting localhost and 27017 not giving ip.. going to different channels all doing same getting connected but you did copy paste and its help thanks..
Kaise hua Bhai Mera nhi ho rha
@@bineetjha2268 use shell ip!! as shown in the video very easily u will be connected
hii piyush ... i m getting this error [nodemon] app crashed - waiting for file changes before starting...how to resolve this please suggest
Same... Do u got the solution?
@@pranjalmaurya3832 nhh bhai didnt got the solution
Yes I am also getting this
@@nirmalchouhan3112 stop the nodemon using ctrl+c and read what error u got if i am not wrong ur mongod is not running in terminal so use mongod in terminal and then open another terminal and run mongosh in it and try restart ur nodemon file
@@pranjalmaurya3832 make script like "start":"nodemon filename(like rest.js)" the run npm start
woww thanks bhaiya
if you could tell why i have to use async await and not genreak func, it would be great
Video useful
Thank you🙏
Thanku sir
Master 🎉
Which extension do you use for mongoose, cause im not getting the auto suggestion. Thanks
Thanks
Sir current mongo db version are very different process for windows and connectivity 😮😮😮
Appreciated
Is there any github repo for this code, so that i can have starter code and code along this tutorial ?
Thankyou sir
Thanks bro
Hello Piyush,
Nice tutorials, But I couldn't get intellisense for mongo CRUD method, how to get that? Pls help
great video
Sir you should also give code if you give code then it will be very easy for us for coding
Can you please share the source-code for this program.
such a nic video
mongosh is not running on my terminal, what to do sir?
Sir I want to ask here that how can I connect mongoDb if I am doing it for the website of my client, because here we are saving data in our local machine but what if I want data to be saved in my clients computer. Please give me solution.
You need to use cloud services then. It's just about having a machine online that runs on cloud.
bhaiya mongodb connect karne ke baad mongodbconnected likha nhi aarha aur ulta mongoose server selection error aa rha hai topology vaguer se related, please help!
MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
I'm facing this error while connecting mongodb
Can you help me ??
Can you paste your code, or mongodb url that you are trying to use?
do not copy full url in the mongosh terminal just we have to copy some part, check it again
how to install mongodb for windows . and after installation of msi file of mongodb how to run mongodb in command prompt ? pls help
search yt please bro there are tons of vids out there!
finally samajh aaya ab jakar
mongo db ka interface to dikha deta, how it is lookd like , i unable to add data manually in mongo db
10:34 male kyu female hi rehne dete 😢😂
Sir humara status 400 bad request aara hai 201 ke jaghe per
Kya kare??
same error get 400 inplace of 201. Please resolve the error
same error how to resolve this issue plz sir reply
Here we are using blocking code while working with database. I assume it's ok for small application but when data becomes very large who we will handle that ? Onw way might be to use promises and on then we can send response. is there any other way ?
bro wo depricated wala error kaise hataye please reply
sir can you also give us the code...it would be helpful to understand more easily then
maja aa gaya
❤
Bhai mongosh keyword work nahi kar Raha hai in windows
Phele mongo shell install kro
run a command "Gussa ho kya Mongosh"
Are required: true and unique: true not valid now??
Bhai agar aapka full stack ho gya ho toh kuch tips doge ?? Mene js me project km bnaiye aur ye playlist follow kr raha hu.. koi dikkat toh ni hogi aapne jo difficulties face kri aur unko kaise handle kra bata sakte ho??
can we get the codebase or github link for this
Why do you need that? Are the tutorials not enough to make you understand everything? If not, you need to really work on the basics first because this is indeed a very basic video
Sit, I am trying to create API for registered users but i am getting error-
Error registering user: MongoServerError: E11000 duplicate key error collection: property.users index: gender_1 dup key: { gender: "Female" }
at InsertOneOperation.execute (D:\sanjay
eact\sidhu-mearn\server
ode_modules\mongodb\lib\operations\insert.js:51:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async executeOperation (D:\sanjay
eact\sidhu-mearn\server
ode_modules\mongodb\lib\operations\execute_operation.js:136:16)
at async Collection.insertOne (D:\sanjay
eact\sidhu-mearn\server
ode_modules\mongodb\lib\collection.js:155:16) {
errorResponse: {
index: 0,
code: 11000,
errmsg: 'E11000 duplicate key error collection: property.users index: gender_1 dup key: { gender: "Female" }',
keyPattern: { gender: 1 },
keyValue: { gender: 'Female' }
},
index: 0,
code: 11000,
keyPattern: { gender: 1 },
keyValue: { gender: 'Female' },
[Symbol(errorLabels)]: Set(0) {}
}
Sir, phone, email should not be same but user name, Hobbies, gender, Image could be same.... Kindly guide me... I am beginner
2:30
Are bhai findById() method to chal hi nhi Rahi hai
Can anyone had complete code tilll this video??
source code bhi de diya karo 🙃
@everyone please if anyone had complete code till this video please share it in comment..
8:07
siurce code kha h
done
0:25
Vid - 19✅
bro sukriya bhagwaan acchi bahu de
😂😂