Connecting NodeJS with MongoDB | Mongoose + Express

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ม.ค. 2023
  • Hey Everyone, In this video, we are going to connect our Node application to MongoDB using mongoose.
    Download MongoDB: www.mongodb.com/docs/manual/a...
    ► 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.dev
    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

ความคิดเห็น • 121

  • @RohitKumar-dy2gc
    @RohitKumar-dy2gc 4 หลายเดือนก่อน +4

    so much new things i am learning easily from these videos✨✨

  • @bhawnachowdhary5466
    @bhawnachowdhary5466 2 หลายเดือนก่อน +1

    Amazing series.. Sir you make everything so simple.. Thanks a lot🙏🙏

  • @jorrgecvx21
    @jorrgecvx21 10 หลายเดือนก่อน +1

    Thanks you, with that video is easy learning mongo and node express

  • @poojaganvir5631
    @poojaganvir5631 5 หลายเดือนก่อน

    Thank you so much. You have explained very well!😊

  • @iamakashkumarram
    @iamakashkumarram ปีที่แล้ว +2

    Bohoti tagri explanation ha bhaiya maja a gaya 🔥🔥

  • @tfnt3839
    @tfnt3839 ปีที่แล้ว +3

    great way of explanation 🙏

  • @CricketHighlights-nt7nn
    @CricketHighlights-nt7nn 10 หลายเดือนก่อน

    yes, ur tutorial solve my problems...thanks a lot boss

  • @Ari-pq4db
    @Ari-pq4db 2 หลายเดือนก่อน

    Thank you very much, keep them coming ❤

  • @user-zv6uv1ei2n
    @user-zv6uv1ei2n 10 หลายเดือนก่อน +2

    appreciated 💯... sir
    Also make tutorial on nodejs framework(nestJs).

  • @sumirandahal76
    @sumirandahal76 4 หลายเดือนก่อน

    thanks a lot piyush sir great teacher and mentor

  • @user-ib1mo9bt5h
    @user-ib1mo9bt5h 5 วันที่ผ่านมา +1

    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.

    • @tusharsingh1915
      @tusharsingh1915 3 วันที่ผ่านมา

      Instead, right now you can create copy of previous videos:)

  • @mojo005m
    @mojo005m 11 หลายเดือนก่อน +1

    Is there any github repo for this code, so that i can have starter code and code along this tutorial ?

  • @user-ww5vy9ws3y
    @user-ww5vy9ws3y 3 หลายเดือนก่อน

    thanks alot finally got it how it works

  • @saisameer780
    @saisameer780 6 หลายเดือนก่อน

    God Level Explaining !!!!!!!!!!!!

  • @CodeLife05
    @CodeLife05 6 หลายเดือนก่อน

    great explanation

  • @namannema3349
    @namannema3349 2 หลายเดือนก่อน +1

    nice explanation bhaiya

  • @ibntofajjal
    @ibntofajjal ปีที่แล้ว +1

    amazing 🔥

  • @vasanthsai1727
    @vasanthsai1727 หลายเดือนก่อน

    Great explanation.

  • @mma-dost
    @mma-dost ปีที่แล้ว +2

    Great videos bhaiya ❤❤🔥🔥🔥🔥💪💪

  • @relaxingtime2411
    @relaxingtime2411 8 หลายเดือนก่อน

    Great video 👍

  • @awesomeguy6427
    @awesomeguy6427 ปีที่แล้ว +1

    Hi Piyush please make a project based on this series

  • @aviii24x7
    @aviii24x7 19 วันที่ผ่านมา

    if you could tell why i have to use async await and not genreak func, it would be great

  • @AYUSHKUMAR-xj4wc
    @AYUSHKUMAR-xj4wc 6 หลายเดือนก่อน

    Awesome❤❤❤

  • @user-su7eh6yr7k
    @user-su7eh6yr7k 5 หลายเดือนก่อน

    Awesome 👍

  • @kartikrastogi1069
    @kartikrastogi1069 11 หลายเดือนก่อน

    The best ❤❤

  • @sohamnoob9062
    @sohamnoob9062 7 วันที่ผ่านมา

    Which extension do you use for mongoose, cause im not getting the auto suggestion. Thanks

  • @worldcricket3030
    @worldcricket3030 หลายเดือนก่อน

    Awesome video

  • @hetjayeshbhaipatel1075
    @hetjayeshbhaipatel1075 3 หลายเดือนก่อน

    woww thanks bhaiya

  • @VishalMishraYouTube
    @VishalMishraYouTube 11 หลายเดือนก่อน +4

    bro, you've been sent by God 🙏

    • @semicolon6499
      @semicolon6499 8 หลายเดือนก่อน

      😅

    • @saarza9991
      @saarza9991 5 วันที่ผ่านมา

      ​@@semicolon6499 ;

  • @rikishi555
    @rikishi555 ปีที่แล้ว

    Thank you🙏

  • @iamakashkumarram
    @iamakashkumarram ปีที่แล้ว +3

    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.

    • @Black-Curtains
      @Black-Curtains ปีที่แล้ว +1

      Theek hai baccha - will cover

  • @relaxwithsoul1599
    @relaxwithsoul1599 6 หลายเดือนก่อน

    Hello Piyush,
    Nice tutorials, But I couldn't get intellisense for mongo CRUD method, how to get that? Pls help

  • @coolgolucool
    @coolgolucool 10 หลายเดือนก่อน

    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..

    • @bineetjha2268
      @bineetjha2268 4 หลายเดือนก่อน

      Kaise hua Bhai Mera nhi ho rha

    • @coolgolucool
      @coolgolucool 4 หลายเดือนก่อน

      @@bineetjha2268 use shell ip!! as shown in the video very easily u will be connected

  • @govindkrishnamishra-km8tj
    @govindkrishnamishra-km8tj 10 หลายเดือนก่อน

    great video

  • @HarpreetSingh-pi1ki
    @HarpreetSingh-pi1ki 3 หลายเดือนก่อน

    Thankyou sir

  • @warrior_pk
    @warrior_pk ปีที่แล้ว +2

    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 ?

    • @piyushgargdev
      @piyushgargdev  ปีที่แล้ว +3

      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

    • @warrior_pk
      @warrior_pk ปีที่แล้ว +1

      @@piyushgargdev thank u, worked for me..

  • @SulavGhimireeee
    @SulavGhimireeee 6 หลายเดือนก่อน

    Thanks bro

  • @MuhammadAdeel-wn9zq
    @MuhammadAdeel-wn9zq 9 หลายเดือนก่อน

    Appreciated

  • @DevZen__
    @DevZen__ 8 หลายเดือนก่อน +2

    Can you please share the source-code for this program.

  • @user--84
    @user--84 ปีที่แล้ว +2

    Sir you should also give code if you give code then it will be very easy for us for coding

  • @bulbbulb6538
    @bulbbulb6538 ปีที่แล้ว

    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.

    • @sureshbhatt363
      @sureshbhatt363 11 หลายเดือนก่อน

      You need to use cloud services then. It's just about having a machine online that runs on cloud.

  • @lovelymusic3549
    @lovelymusic3549 ปีที่แล้ว +3

    Sir will you upload a complete course of mern stack?

  • @sureshbhatt363
    @sureshbhatt363 11 หลายเดือนก่อน +3

    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.

    • @messi_codes
      @messi_codes 10 หลายเดือนก่อน

      use try and catch method it will handle the server crash case

    • @vivekraiyani63
      @vivekraiyani63 5 หลายเดือนก่อน

      same issue bro

    • @sureshbhatt363
      @sureshbhatt363 5 หลายเดือนก่อน

      @@vivekraiyani63 using Try and Catch method solved the problem

    • @Chaudharyhammad
      @Chaudharyhammad 5 หลายเดือนก่อน

      1st check for email if it already exists then throw and error message and if not then proceeds further

    • @SwatejTech
      @SwatejTech 5 หลายเดือนก่อน

      Add a middleware to check if the user already exists before proceeding to the insertion.

  • @Dhruv-gl4sv
    @Dhruv-gl4sv 6 หลายเดือนก่อน

    Are required: true and unique: true not valid now??

  • @ramendrasoni3368
    @ramendrasoni3368 หลายเดือนก่อน +1

    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 ..

  • @saranyasingh6847
    @saranyasingh6847 ปีที่แล้ว

    how to install mongodb for windows . and after installation of msi file of mongodb how to run mongodb in command prompt ? pls help

    • @anandshete9170
      @anandshete9170 5 หลายเดือนก่อน

      search yt please bro there are tons of vids out there!

  • @vikashbisht6097
    @vikashbisht6097 4 หลายเดือนก่อน +1

    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

    • @UmaisKhan-gs1th
      @UmaisKhan-gs1th 10 วันที่ผ่านมา

      hn bhai 4 mahine hogay... bangya?

  • @nishu20501
    @nishu20501 2 หลายเดือนก่อน

    finally samajh aaya ab jakar

  • @sushantlama2178
    @sushantlama2178 ปีที่แล้ว

    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 ??

    • @piyushgargdev
      @piyushgargdev  ปีที่แล้ว +1

      Can you paste your code, or mongodb url that you are trying to use?

    • @eswarsai5163
      @eswarsai5163 2 หลายเดือนก่อน

      do not copy full url in the mongosh terminal just we have to copy some part, check it again

  • @harshalmali856
    @harshalmali856 6 หลายเดือนก่อน

    bro wo depricated wala error kaise hataye please reply

  • @nirmalchouhan3112
    @nirmalchouhan3112 7 หลายเดือนก่อน +1

    hii piyush ... i m getting this error [nodemon] app crashed - waiting for file changes before starting...how to resolve this please suggest

    • @pranjalmaurya3832
      @pranjalmaurya3832 4 หลายเดือนก่อน

      Same... Do u got the solution?

    • @nirmalchouhan3112
      @nirmalchouhan3112 4 หลายเดือนก่อน

      @@pranjalmaurya3832 nhh bhai didnt got the solution

    • @bineetjha2268
      @bineetjha2268 4 หลายเดือนก่อน

      Yes I am also getting this

    • @coolgolucool
      @coolgolucool 4 หลายเดือนก่อน

      @@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

  • @user-ig9hd2hg3k
    @user-ig9hd2hg3k ปีที่แล้ว

    can we get the codebase or github link for this

    • @sureshbhatt363
      @sureshbhatt363 11 หลายเดือนก่อน

      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

  • @amandhurwey7964
    @amandhurwey7964 4 หลายเดือนก่อน

    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 ?

    • @whyDude123
      @whyDude123 3 หลายเดือนก่อน +1

      At the end, he literally said that we are going to refactor the code according to industrial standards. Looks like you missed that part

  • @TrainwithrohitT
    @TrainwithrohitT 20 วันที่ผ่านมา

    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!

  • @ramswrooppatidar7599
    @ramswrooppatidar7599 24 วันที่ผ่านมา

    mongo db ka interface to dikha deta, how it is lookd like , i unable to add data manually in mongo db

  • @rohitsoni3710
    @rohitsoni3710 2 หลายเดือนก่อน

    maja aa gaya

  • @gunjannankani4419
    @gunjannankani4419 7 หลายเดือนก่อน +1

    Sir humara status 400 bad request aara hai 201 ke jaghe per
    Kya kare??

    • @prabhakumari7026
      @prabhakumari7026 28 วันที่ผ่านมา

      same error get 400 inplace of 201. Please resolve the error

    • @sidratahir3728
      @sidratahir3728 16 วันที่ผ่านมา

      same error how to resolve this issue plz sir reply

  • @Kabirrsaini07
    @Kabirrsaini07 2 หลายเดือนก่อน

    sir can you also give us the code...it would be helpful to understand more easily then

  • @amitpatel0716
    @amitpatel0716 11 หลายเดือนก่อน

    Are bhai findById() method to chal hi nhi Rahi hai

  • @ShivendraPratap524
    @ShivendraPratap524 ปีที่แล้ว +1

    done

  • @saxenabhavesh6941
    @saxenabhavesh6941 6 หลายเดือนก่อน +2

    Your explanation is good but the code looks so bad , use different code for each video so we can understand it better manner ..

    • @nop9974
      @nop9974 หลายเดือนก่อน

      Tare to karvu nahi.. bija kare aene to krvada. Bencbod

  • @Ympatel1912
    @Ympatel1912 หลายเดือนก่อน +1

    Bhai mongosh keyword work nahi kar Raha hai in windows

  • @arjunyadav-kt5jr
    @arjunyadav-kt5jr 4 หลายเดือนก่อน

    plural Tense!

  • @iamgautamsuthar
    @iamgautamsuthar 3 หลายเดือนก่อน

    2:30

  • @bunnytheweebster
    @bunnytheweebster 6 หลายเดือนก่อน

    Vid - 19✅

  • @yashvijaybombale6896
    @yashvijaybombale6896 10 หลายเดือนก่อน

    8:07

  • @SuperSanjay99
    @SuperSanjay99 หลายเดือนก่อน

    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

  • @abhisheknavgan6829
    @abhisheknavgan6829 5 หลายเดือนก่อน +1

    5:19 gender should be a enum but in 2024 I think String would be better 😂😂😂😂

  • @rishabhraj8233
    @rishabhraj8233 6 หลายเดือนก่อน

    code for patch method
    patch(async(req,res)=>{
    //edit an existing user
    const id = req.params.id;
    const body = req.body;
    try {
    const user = await User.findById(id);
    if (!user) {
    return res.status(404).json({ status: 'Error', message: 'User not found' });
    }
    // Check for changed properties and update only those that exist in the request body
    Object.keys(body).forEach((key) => {
    if (user[key] !== undefined) {
    user[key] = body[key];
    }
    });
    await user.save();
    return res.json({ status: 'Success', updatedUser: user });
    } catch (err) {
    return res.status(500).json({ status: 'Error', message: 'Internal server error' })}
    })

  • @shi-nee7966
    @shi-nee7966 ปีที่แล้ว

    im crying

  • @gayatrishinde5086
    @gayatrishinde5086 2 หลายเดือนก่อน

    worst ever like others👎

  • @aymenazizi2995
    @aymenazizi2995 ปีที่แล้ว +6

    misleading your title is in English yet you explain in hindi.

    • @AnkitGupta-lr1qq
      @AnkitGupta-lr1qq ปีที่แล้ว +15

      that doesn't make the title misleading..

    • @sauravlakhotia3434
      @sauravlakhotia3434 7 หลายเดือนก่อน +32

      😂 according to u he should write like this
      अनपीयम इंस्टॉल पैकेज-नेम

    • @pkyadav6230
      @pkyadav6230 6 หลายเดือนก่อน +2

      😂 what nuisance u r talking

    • @rajathkumar3822
      @rajathkumar3822 5 หลายเดือนก่อน +3

      Yep bro omitting FACTS 😂.

    • @amitbhagat120
      @amitbhagat120 5 หลายเดือนก่อน

      What kind of stupid you are my dear brother is he mentioned that video is in English?

  • @sumirandahal76
    @sumirandahal76 4 หลายเดือนก่อน

    app.delete("/api/users", async (req, res) => {
    await User.deleteMany({});
    return res.json({ msg: "I screwed up your database, haha" });
    }); 😁😁just intendly deleted all users, don't try hehe