Complete MongoDB Tutorial #16 - Connecting to MongoDB

Complete MongoDB Tutorial #16 - Connecting to MongoDB

Net Ninja

2 года назад

108,880 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Lee Eric
Lee Eric - 15.11.2023 03:08

why don't simply use "const mongoose = require("mongoose");
const connect = await mongoose.connect(connection_string)"

Ответить
MJD
MJD - 11.11.2023 07:52

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

Ответить
aymen boudabia
aymen boudabia - 10.09.2023 17:55

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)

Ответить
Paresh B. Patel
Paresh B. Patel - 01.09.2023 19:16

Connecting to a MongoDB database in NodeJS; so beautifully explained. Thanks, Shaun.

{2023-09-01}

Ответить
Abhi17
Abhi17 - 30.06.2023 18:55

👍

Ответить
Dor.
Dor. - 24.06.2023 00:07

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

Ответить
Shrut Pansuriya
Shrut Pansuriya - 08.05.2023 18:54

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

Ответить
Vishal Gupta
Vishal Gupta - 15.02.2023 05:32

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

Ответить
ARTICO
ARTICO - 18.01.2023 19:51

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

Ответить
Tuấn Nguyễn
Tuấn Nguyễn - 27.12.2022 17:56

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

Ответить
nguyen toan
nguyen toan - 08.11.2022 17:08

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

Ответить
Donn Jazy
Donn Jazy - 07.11.2022 18:11

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

Ответить
Phillip
Phillip - 31.10.2022 09:46

Try to replicate the tutorial, but get error:

TypeError: connectToDb is not a function

Ответить
Less known!
Less known! - 13.10.2022 20:12

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

Ответить
ofeyofey
ofeyofey - 23.09.2022 18:53

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?

Ответить
Code Dynamics
Code Dynamics - 09.08.2022 12:57

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

Ответить
NerfGanondorf
NerfGanondorf - 02.08.2022 07:34

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.

Ответить
ALex
ALex - 06.07.2022 13:24

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;

Ответить
Eric Carver
Eric Carver - 01.06.2022 17:37

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.

Ответить
eskTea
eskTea - 16.04.2022 06:20

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

Ответить
Afroboi
Afroboi - 14.04.2022 14:38

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

Ответить
AveN7ers
AveN7ers - 05.04.2022 14:42

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

Ответить
Abdelaziz Elalfy
Abdelaziz Elalfy - 05.04.2022 10:44

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

Ответить
Okey Shourov Roy
Okey Shourov Roy - 04.04.2022 20:23

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

Ответить
The Majestic Beard
The Majestic Beard - 04.04.2022 18:51

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

Ответить
Michal
Michal - 04.04.2022 17:07

Thank you!

Ответить
GldzzPro
GldzzPro - 04.04.2022 17:00

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

Ответить
Chinedu Henry
Chinedu Henry - 04.04.2022 16:46

Great and awesome thanks Shaun💯👍

Ответить
Rafik Reguig
Rafik Reguig - 04.04.2022 16:22

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

Ответить
Freeman Charles
Freeman Charles - 04.04.2022 13:31

Great Content 👍❤️💡

Ответить
Isaac Qadri
Isaac Qadri - 04.04.2022 13:30

♥️♥️😍

Ответить
Freeman Charles
Freeman Charles - 04.04.2022 13:29

2nd Viewer ❤️🚀

Ответить