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;
What is the difference between connecting with the MongoClient from the mongodb package and connecting with mongoose.connect() with the mongoose package?
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!!!
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.
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.
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
Please also include mongodb aggregation framework with mongooses or mongodb driver (filtering and sorting sub document arrays) geojson. It would be very helpful 🙏🙏
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?
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
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
Not only mongodb conn, you taught node,callback, promise everything so nicely!
Thanks MAN!
lowkey falling in love with his teaching
OK I see why people would rather use Mongoose over the native driver now.
This is fantastic, you make it all so easy to understand!
i love this new mongodb tutorial but if you make a mongoose tutorial as well it will be fantastic
A big love for you Shaun 💛, splendid content thank you so much
Excellent series!
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;
typo:
let dbConnection is defined, dont put const in front of it inside the connectToDb function. Just re-assign it.
What is the difference between connecting with the MongoClient from the mongodb package and connecting with mongoose.connect() with the mongoose package?
hope u find out can u help me i'm struggling same conncetin mongo to node js
Connecting to a MongoDB database in NodeJS; so beautifully explained. Thanks, Shaun.
{2023-09-01}
Great and awesome thanks Shaun💯👍
Thank you!
the err var at the cb will be undefined and not null :)
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!!!
Glad this helped you Vishal :)
@@NetNinja Try to replicate the tutorial, but get error:
TypeError: connectToDb is not a function
Why you need to use "return cb()" instead of "cb()"?
Great Content 👍❤️💡
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.
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.
Just keep pushin button!
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
It's not about mongodb driver ,it's all about express and server creation I wait for the next episode today ,please
This *is* about the MongoDB driver. I think you meant to comment on the previous video.
Please also include mongodb aggregation framework with mongooses or mongodb driver (filtering and sorting sub document arrays) geojson. It would be very helpful 🙏🙏
thank you
You're welcome!!
I have a question, Why do we return the callback? why not just call it?
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
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.
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?
You have just over complicated things using that methodology. Use simple connection without any callbacks + using async await
why not just require this file and the code and connection can be done just in the file itself and just export dbConnection?
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)
Sir, please what's your vscode theme? i like the IDE coloring
3:16 could there be another method for url on local machine. I don’t know why this one didn’t connect
I get error: SyntaxError: Unexpected token, when: const { MongoClient } = require('mongodb');
Can you please help me to fix it! Thank you so much.
why couldn't we just call dbConnection as getDb and cal that getDb instead of putting dbConnection into a function and call thta function?
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
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
did you find the source code?
Try to replicate the tutorial, but get error:
TypeError: connectToDb is not a function
Same error
same error, did you solve it already?
grtting error in this line: dbConnection = client.db(); Error: "Error [MongoError]: database name must be a string"
👍
♥️♥️😍
2nd Viewer ❤️🚀
295th viewer ❤🚀