Complete MongoDB Tutorial #16 - Connecting to MongoDB

Поделиться
HTML-код
  • Опубликовано: 16 ноя 2024

Комментарии • 52

  • @lessknownindeed
    @lessknownindeed 2 года назад +12

    Not only mongodb conn, you taught node,callback, promise everything so nicely!
    Thanks MAN!

  • @kingwillex5708
    @kingwillex5708 День назад

    lowkey falling in love with his teaching

  • @AveN7ers
    @AveN7ers 2 года назад +26

    OK I see why people would rather use Mongoose over the native driver now.

  • @themajesticbeard1497
    @themajesticbeard1497 2 года назад +6

    This is fantastic, you make it all so easy to understand!

  • @gldzzpro5793
    @gldzzpro5793 2 года назад +11

    i love this new mongodb tutorial but if you make a mongoose tutorial as well it will be fantastic

  • @rafikreguig4006
    @rafikreguig4006 2 года назад +3

    A big love for you Shaun 💛, splendid content thank you so much

  • @thor_
    @thor_ 4 месяца назад +1

    Excellent series!

  • @alexpiano
    @alexpiano 2 года назад +6

    Case anyone feels alergic to .then().catch() here's my async/await code:
    const { MongoClient } = require('mongodb');
    let dbConnection;
    const uri = 'mongodb://localhost:27017/bookstore';
    // Connect to the database
    exports.connectToDb = async (cb) => {
    // a callback function is passed, and it will be executed when the following task is completed.
    try {
    const client = await MongoClient.connect(uri);
    const dbConnection = client.db();
    return cb();
    } catch (error) {
    console.log(error);
    return cb(error);
    }
    };
    // Return the database connection so we can play with it (make queries)
    exports.getDb = () => dbConnection;

    • @alexpiano
      @alexpiano 2 года назад +2

      typo:
      let dbConnection is defined, dont put const in front of it inside the connectToDb function. Just re-assign it.

  • @eskTea
    @eskTea 2 года назад +8

    What is the difference between connecting with the MongoClient from the mongodb package and connecting with mongoose.connect() with the mongoose package?

    • @ashutosh_sah8537
      @ashutosh_sah8537 11 месяцев назад

      hope u find out can u help me i'm struggling same conncetin mongo to node js

  • @Pareshbpatel
    @Pareshbpatel Год назад

    Connecting to a MongoDB database in NodeJS; so beautifully explained. Thanks, Shaun.
    {2023-09-01}

  • @chineduhenry3126
    @chineduhenry3126 2 года назад

    Great and awesome thanks Shaun💯👍

  • @michal3833
    @michal3833 2 года назад +1

    Thank you!

  • @dor.332
    @dor.332 Год назад

    the err var at the cb will be undefined and not null :)

  • @vishalgupta8203
    @vishalgupta8203 Год назад +2

    Thank you so much for creating this session, I have seen lot of mongodb connection but they max are using mongoose and either they are not creating one db as dynamic and globally available but your this session helped me now I am stopped my searching.
    Thanks a lot!!!

    • @NetNinja
      @NetNinja  Год назад

      Glad this helped you Vishal :)

    • @marlonr.pedrasitajr.3751
      @marlonr.pedrasitajr.3751 Год назад +1

      @@NetNinja Try to replicate the tutorial, but get error:
      TypeError: connectToDb is not a function

  • @tuannguyen5904
    @tuannguyen5904 Год назад +1

    Why you need to use "return cb()" instead of "cb()"?

  • @freemancharles2491
    @freemancharles2491 2 года назад

    Great Content 👍❤️💡

  • @ericcarver7465
    @ericcarver7465 2 года назад

    Do you ever have a sale on your annual pro plan? It's a great price don't get me wrong, just at a frugal point in my life --- yet I love your teaching style and want to pay for the learning buffet you've put out for me.

  • @ghostaccountlmao
    @ghostaccountlmao 2 года назад +1

    I'm not gonna lie I have no idea what's going on anymore but at this point I think I'm just supposed to stop forcing myself to clearly understand everything and just get the practice in.

    • @ofeyofey
      @ofeyofey 2 года назад

      Just keep pushin button!

  • @mjd7691
    @mjd7691 Год назад

    About that CB function , couldn't we just put it in THEN and with no property ? , if the connection successfully established we will listen to the port if not we just won't do anything

  • @abdelazizelalfy1922
    @abdelazizelalfy1922 2 года назад

    It's not about mongodb driver ,it's all about express and server creation I wait for the next episode today ,please

    • @AveN7ers
      @AveN7ers 2 года назад

      This *is* about the MongoDB driver. I think you meant to comment on the previous video.

  • @okeyshourovroy2769
    @okeyshourovroy2769 2 года назад +2

    Please also include mongodb aggregation framework with mongooses or mongodb driver (filtering and sorting sub document arrays) geojson. It would be very helpful 🙏🙏

  • @abdellahiaioun8430
    @abdellahiaioun8430 Год назад

    thank you

  • @afroboi7454
    @afroboi7454 2 года назад

    I have a question, Why do we return the callback? why not just call it?

  • @codedynamics1
    @codedynamics1 2 года назад +2

    this is like 5th time trying to connect and find the collection and it's just not working. This time im using exact same code

    • @BrunoMCDowell
      @BrunoMCDowell Год назад

      Hey I am experiencing the same issue. I've spent hours on google trying to find a solution but no success. I'm thinking about giving up to be honest.

  • @ofeyofey
    @ofeyofey 2 года назад

    Great tutorial thanks. But where is the connection string found in Atlas? And where do you place the username and password? Is bookstore the database or collection name?

  • @akhatarmourad8221
    @akhatarmourad8221 5 дней назад

    You have just over complicated things using that methodology. Use simple connection without any callbacks + using async await

  • @Ilohimushka
    @Ilohimushka 8 месяцев назад

    why not just require this file and the code and connection can be done just in the file itself and just export dbConnection?

  • @aymenboudabia5221
    @aymenboudabia5221 Год назад

    why you export 2 functions while you can use cb(err,db) with 2 parameters, return cb(null,db) when no error. if there is an error return cb(err)

  • @melchizedek79
    @melchizedek79 2 года назад

    Sir, please what's your vscode theme? i like the IDE coloring

  • @malumbopolela5380
    @malumbopolela5380 Год назад

    3:16 could there be another method for url on local machine. I don’t know why this one didn’t connect

  • @nguyentoanhnt
    @nguyentoanhnt 2 года назад

    I get error: SyntaxError: Unexpected token, when: const { MongoClient } = require('mongodb');
    Can you please help me to fix it! Thank you so much.

  • @art1co
    @art1co Год назад

    why couldn't we just call dbConnection as getDb and cal that getDb instead of putting dbConnection into a function and call thta function?

  • @yazan5790
    @yazan5790 7 месяцев назад

    guys, i need help, is this the only way to create the connection with mongodb?? this is so complicated for me, way to many steps and way too many unkowns....if anyone has a better way or better tutorial please let me know, thanks

  • @hoangphanhuy1992
    @hoangphanhuy1992 2 года назад

    how can i get the source code? i open github link below the video but it told me that file is on this youtube channel, btw i can not find it. Anyone help me, pls send me a link or way to get database file? tks

  • @phillip76
    @phillip76 2 года назад

    Try to replicate the tutorial, but get error:
    TypeError: connectToDb is not a function

  • @shrutpansuriya7987
    @shrutpansuriya7987 Год назад

    grtting error in this line: dbConnection = client.db(); Error: "Error [MongoError]: database name must be a string"

  • @Abhi-oh2ps
    @Abhi-oh2ps Год назад

    👍

  • @towatch
    @towatch 2 года назад

    ♥️♥️😍

  • @freemancharles2491
    @freemancharles2491 2 года назад

    2nd Viewer ❤️🚀