
Build a Node.js API - tutorial
video description
Date: 2022-03-14
Related videos
Comments and reviews: 10
marverati
22:30 at that point I get the error -db.collection is not a function-. It seems a few things are different with MongoDB Atlas, since mLab doesn't work as presented in the video anymore.
What I needed to do was follow the instructions of MongoDB Atlas to set everything up, then go to Clusters, my created cluster, click 'Connect' > 'Connect Your Application', there's a) the URL we need and, when clicking 'Full Driver Example', I can see why I receive the above error message. With this it seems to work:
const client = new MongoClient(db.url, - useNewUrlParser: true -)
client.connect(err => -
if (err) return console.log(err)
const db = client.db(-databaseName-)
require('./app/routes')(app, db);
app.listen(port, () => -
console.log(-We are live on - + port);
-);
-)
Where databaseName is however you want your database to be called. This way the -db.collection(...)- call within the routes files will work.
reply
22:30 at that point I get the error -db.collection is not a function-. It seems a few things are different with MongoDB Atlas, since mLab doesn't work as presented in the video anymore.
What I needed to do was follow the instructions of MongoDB Atlas to set everything up, then go to Clusters, my created cluster, click 'Connect' > 'Connect Your Application', there's a) the URL we need and, when clicking 'Full Driver Example', I can see why I receive the above error message. With this it seems to work:
const client = new MongoClient(db.url, - useNewUrlParser: true -)
client.connect(err => -
if (err) return console.log(err)
const db = client.db(-databaseName-)
require('./app/routes')(app, db);
app.listen(port, () => -
console.log(-We are live on - + port);
-);
-)
Where databaseName is however you want your database to be called. This way the -db.collection(...)- call within the routes files will work.
reply
Deon
Thanks man great tutorial, just an FYI in the year 2020 after MongoDb version 3 was released the database connection doesn't return a database object it returns a client object and as a sub-object to the client object you can access the database object so now if you want to indicate a collection it's client.db('notes').
reply
Thanks man great tutorial, just an FYI in the year 2020 after MongoDb version 3 was released the database connection doesn't return a database object it returns a client object and as a sub-object to the client object you can access the database object so now if you want to indicate a collection it's client.db('notes').
reply
Caroline
thank you for the tutorial, mLab is no longer accepting new customers and redirects to mongoDb Atlas. could you tell how to proceed to create the db since I could not find the same menus on this new platform?otherwise, is it possible to create the db through the terminal? thank you very much for your answer
reply
thank you for the tutorial, mLab is no longer accepting new customers and redirects to mongoDb Atlas. could you tell how to proceed to create the db since I could not find the same menus on this new platform?otherwise, is it possible to create the db through the terminal? thank you very much for your answer
reply
Json
if i use latest version of mongoose (v5 ?) in dependencies and latest driver 3.0 above, rest of the codes the same. Will it still work?? (currently using 2.2.33, driver 2.2.12 or later....)
reply
if i use latest version of mongoose (v5 ?) in dependencies and latest driver 3.0 above, rest of the codes the same. Will it still work?? (currently using 2.2.33, driver 2.2.12 or later....)
reply
Attack
As of February 2019, mLab does not allow you to create a new account and log in to that account. Instead, you have to use MongoDB Atlas. How can I get my URL from there?
reply
As of February 2019, mLab does not allow you to create a new account and log in to that account. Instead, you have to use MongoDB Atlas. How can I get my URL from there?
reply
Marc
PostMan chrome extension is now deprecated but the desktop app is working well. Same stuff for Mlab which is now MongoDB =).
Thanks for this tutorial !
reply
PostMan chrome extension is now deprecated but the desktop app is working well. Same stuff for Mlab which is now MongoDB =).
Thanks for this tutorial !
reply
M-lanie
Thank you, it was so helpful to build my first api as a non-developer ! With mongoDB cloud atlas and. the trick db.db('database').collection
reply
Thank you, it was so helpful to build my first api as a non-developer ! With mongoDB cloud atlas and. the trick db.db('database').collection
reply
Juan
Are there any rules to set the post number? I've changed 8000 to 3000 and sent the data from Postman, then the Node prompet didn't response.
reply
Are there any rules to set the post number? I've changed 8000 to 3000 and sent the data from Postman, then the Node prompet didn't response.
reply
Marc
Typos everywhere ! :'/
I can't focus on what you say because I get distracted by every typo.
Could have been great otherwise.
reply
Typos everywhere ! :'/
I can't focus on what you say because I get distracted by every typo.
Could have been great otherwise.
reply
Add a review, comment
Other channel videos















