Intro to MongoDB and Mongoose | Node.js Tutorials for Beginners

  Рет қаралды 70,396

Dave Gray

Dave Gray

Күн бұрын

Web Dev Roadmap for Beginners (Free!): bit.ly/DaveGrayWebDevRoadmap
In this intro to MongoDB and Mongoose you will learn how to set up a MongoDB database and connect to it with Mongoose from your Node.js application. MongoDB uses a NoSQL database structure with collections and documents.
🚩 Subscribe ➜ bit.ly/3nGHmNn
🚀 This tutorial is part of a Node.js & Express for Beginners tutorial series playlist:
• Node.js Tutorials for ...
🔗 Starter Source Code: github.com/gitdagray/express_...
🔗 Completed Source Code: github.com/gitdagray/mongodb_...
Intro to MongoDB and Mongoose | Node.js Tutorials for Beginners
(00:00) Intro
(00:05) Welcome
(00:16) What is NoSQL and MongoDB?
(02:05) Sign up for a MongoDB account
(02:39) Create a MongoDB database
(05:14) Create a database user
(06:15) Get the database connection string
(07:37) Project Source Code
(07:54) Place the connection string in dotenv
(08:53) dotenv adjustment
(10:04) Install mongoose dependency
(11:14) Connect app to MongoDB
🌱 MongoDB and Mongoose References:
MongoDB: www.mongodb.com/
Mongoose: mongoosejs.com/
📚 JWT References:
Intro to JSON Web Tokens: jwt.io/introduction
All You Need to Know About Storing JWT in the Frontend: dev.to/cotter/localstorage-vs...
NPM jsonwebtoken package: www.npmjs.com/package/jsonweb...
NPM cookie-parser package: www.npmjs.com/package/cookie-...
Deleting Cookies: expressjs.com/en/api.html#res....
Cross-Site Scripting (XSS): owasp.org/www-community/attac...
Cross-Site Request Forgery (CSRF): owasp.org/www-community/attac...
REST Security Cheat Sheet: cheatsheetseries.owasp.org/ch...
📚 Login References:
Bcrypt: www.npmjs.com/package/bcrypt
How to Safely Store a Password: codahale.com/how-to-safely-st...
MDN: HTTP Response Status Codes: developer.mozilla.org/en-US/d...
📚 More References:
Node.js Official site: nodejs.org
NPM Official site: www.npmjs.com/
Express JS Official site: expressjs.com/
MDN CORS: developer.mozilla.org/en-US/d...
NPM CORS: www.npmjs.com/package/cors
✅ Follow Me:
Twitter: / yesdavidgray
LinkedIn: / davidagray
Blog: yesdavidgray.com
Reddit: / daveoneleven
Was this tutorial intro to MongoDB and Mongoose with Node.js helpful? If so, please share. Let me know your thoughts in the comments.
#mongodb #mongoose #nodejs

Пікірлер: 77
@yonathanhailemelekot5238
@yonathanhailemelekot5238 2 жыл бұрын
I bet. This is most precious mongodb content in the entire universe
@judithkoelewijn7317
@judithkoelewijn7317 2 жыл бұрын
This was perfect! Straight forward, easy to follow and succeeded with a connection. Thanks!!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome, Judith! 💯
@elrubio8091
@elrubio8091 2 жыл бұрын
@Dave Gray Thank you for making this tutorial simple enough for us beginner to understand better!!! Just what i need it!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome! 💯
@yoshi8171
@yoshi8171 2 жыл бұрын
You've read my mind! This is exactly what I was expecting right after Node/Express. Great!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad to help! I wanted to cover the full MERN stack when combining this Node.js series with my React tutorials. 🚀
@lavitzwind6709
@lavitzwind6709 2 жыл бұрын
@@DaveGrayTeachesCode, it would fantastic if in the end, you can build MERN projects. Using all of the knowledge acquired.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
@@lavitzwind6709 yes, this series delivers the backend of the MERN stack (Node, Express, Mongo) so when combined with my React tutorials, full MERN projects may be completed. I'll be posting MERN projects, too.
@samirsamir7779
@samirsamir7779 2 жыл бұрын
your explanations are just perfect Dave , I would have liked to know your channel before all the courses purchased here and there ... I really expect a ton of videos from you ( PHP , Symfony , Sass please ...etc ) . Thank you Dave :)
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome! And thank you for the requests. 🚀
@phoenifiresky6344
@phoenifiresky6344 Жыл бұрын
Tank you for this video I really needed this! You did an amazing job!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're so welcome!
@ogundekoadegbenga3766
@ogundekoadegbenga3766 Жыл бұрын
Thanks Dave. 👍
@abdullahsevmez42
@abdullahsevmez42 2 жыл бұрын
you're from another planet bro 💯😊what you're doing now it's perfect, keep going and I'm sharing your channel even in my WhatsApp story daily 😊 I'm here to help you whenever you need 🤜🤛
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you so much Abdullah! I appreciate you sharing. 💯🚀
@abdullahsevmez42
@abdullahsevmez42 2 жыл бұрын
@@DaveGrayTeachesCode you're welcome dave! 🤜🤛👩‍💻Keep going 🤗
@brienfoaboutanything9037
@brienfoaboutanything9037 2 жыл бұрын
Thats amazing information about Mongoose: kzbin.info/www/bejne/pqHHmXpmic5_n9k
@ilyesbejia6566
@ilyesbejia6566 2 жыл бұрын
Those are great tutorials thanks for sharing !!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome! 💯
@danidan4565
@danidan4565 2 жыл бұрын
Thank you so much for the lessons I've really learned a lot
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Great to hear Dani!
@jmgomw7787
@jmgomw7787 2 жыл бұрын
Very well explain! it has been very useful!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad I could help!
@deathdefier45
@deathdefier45 2 жыл бұрын
You're my hero Dave
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you for the kind words! 🙏💯
@yekaterinacrawford2037
@yekaterinacrawford2037 2 жыл бұрын
Thank you, Dave! Please make video series about Angular :)
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome! And Thank you for the request 💯
@sonamohialdin3376
@sonamohialdin3376 2 жыл бұрын
Awesome tutorial thank you
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome, Sona! 💯
@juangomez874
@juangomez874 2 жыл бұрын
An excellent tutorial like all the others. Thanks, Dave. Thanks for the advice: "Keep striving for progress over perfection". This is the key. What do you think about doing a tutorial about NextJS?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome! NextJS is a great idea and something I definitely plan to cover 💯🚀
@suprabhatkumar5478
@suprabhatkumar5478 2 жыл бұрын
Great tutorial 👍
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you! Cheers!
@kove5762
@kove5762 Жыл бұрын
Your explanation is amazing! I wish you were proffesor in my college...
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you!
@fares.abuali
@fares.abuali 2 жыл бұрын
Great 👏
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thanks!
@internet_glen
@internet_glen Жыл бұрын
"testing123... kinda like a mic check". dave you are a backend rockstar
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you! 🎸🤘🙏
@venkatesannedumaran6489
@venkatesannedumaran6489 Жыл бұрын
super we need advanced tutorial for same topic
@cloud_architector
@cloud_architector 2 жыл бұрын
Nice
@sashaikevich
@sashaikevich 2 жыл бұрын
Have you got videos of you setting up this project? I see everything is well documented and organized. I’d like to be able to follow along to better understand how you decide to write your middleware. What you choose to log. Why the credential check is before CORS etc.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Hi Sasha, good questions! I do not have videos setting up the project. I just make the tutorials. To answer the specifics you mentioned: I write the middleware based on need only. I only log things during development to see the values myself or during a tutorial to show as an example. The credential middleware is referencing the 'Access-Control-Allow-Credentials' which is sent back because browsers will send a preflight OPTIONS request before sending the intended POST (or other) request from the frontend. If it doesn't pass preflight, it will block the intended request. More on that on MDN here (look for 'Preflighted Request" subheading): developer.mozilla.org/en-US/docs/Web/HTTP/CORS
@sashaikevich
@sashaikevich 2 жыл бұрын
@@DaveGrayTeachesCode thanks! I actually did find what I was looking for since commenting. Turns out this video is part of a larger Node playlist, and I'm slowly making my way through those. Thanks! I subbed.
@swanne22
@swanne22 2 жыл бұрын
Hi Dave. Thank you so much for this tutorial series. Just completed this one and was presented with an error informing me of a deprecated function: - MongoParseError: option usernewurlparser is not supported After commenting that line out of the dbConn.js file the connection works. Are there any problems that not having this line in my code will cause?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Hi Carl, technology keeps moving forward. Features will be deprecated and new ones will be added. I suggest following the info provided by the deprecation notice and all should be well.
@swanne22
@swanne22 2 жыл бұрын
@@DaveGrayTeachesCode Thank you. Really appreciate it
@NaviaryMusic
@NaviaryMusic Жыл бұрын
I would like my web server to be entirely located on my device. I have also experienced some corruptions that happen with the built in fs (file system) occasionally erasing json files. I think it might happen when fs tries to read and write a file at the same time. What would you recommend I do if I wanted everything to remain on my pc? Is there a more stable alternative to using fs? Or a way to prevent the occasional json file deletion?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
I used JSON in the first part of this series, but starting at this video, I switch things over to MongoDB which I recommend. You can install MongoDB on your PC if you want.
@manikantaprasadlopinti8375
@manikantaprasadlopinti8375 2 ай бұрын
The Read operations are slow compared to sql.. only write operations are faster in no-sql
@igrknk
@igrknk Жыл бұрын
Hello Dave! In PHP and MySQL, before each query, the script needs to connect to the database first. In node.js, if I put the connection to mongoDB in the file that runs the application (in your example 'server.js'), then I don't need to connect to the database before each query? Thanks in advance!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Yes, from the source code in the course resources: github.com/gitdagray/mongo_async_crud/blob/main/server.js You can see on lines 16 & 17 that connecting to the database is the first thing we do. Then on line 65, we listen for that connection.
@igrknk
@igrknk Жыл бұрын
@@DaveGrayTeachesCode Thanks a lot for the explanation!
@igrknk
@igrknk Жыл бұрын
@@DaveGrayTeachesCode One more thing: in node/express you don't need to close the database connection? Or does this only apply to mongodb?
@UdhayaKumar-me2lt
@UdhayaKumar-me2lt 5 ай бұрын
can able to access the routes like register, auth from your cloned code it just display unauthorized
@DaveGrayTeachesCode
@DaveGrayTeachesCode 5 ай бұрын
Yes, if you just clone the code and don't work through the course, you will miss some things.
@cianmoriarty7345
@cianmoriarty7345 Жыл бұрын
You can't throw out normalisation without consequences in a no SQL database any more than you can in SQL. Sure SQL database designer stress it more, but it is entirely up to whoever creates the schema to ensure there's no room for redundancies (except for keys) in that schema. More about that later. But there's nothing _in_ SQL that forces you to normalise your schema and hence data. You can store redundant data in SQL as easily as MongoDB or indeed paper files. In any case the effect of _not_ normalising is the same: potentially redundant data that becomes contradictory and therefore wrong when you edit it. Because you forgot where you put all the copies and so when you did an one or more didn't get updated properly because you forgot about it or accidentally used different data for one. Even with psuedo SQL you can normalise to third normal form and be fairly sure this just can't happen. Unless for instance you did misidentified what needs to be 'an entity', eg, you did something like hard bake all address details into your person table, because you were convinced you'd never, ever, need to consider an address as something separate from an individual person. Which is clearly not true, because people change their address all the time... A "proper" SQL implementation will give you ways of ensuring the rules YOU put in are followed, but there's nothing forcing you to put them in in the first place, and indeed in many so called SQL implementations such as MySQL for instance much of this rule enforcement is either missing or turned off by default. Except that pretty much always you have to make a special arrangement to store than one thing in every intersection of row and column, and usually all rows in a table must have the same number and type of columns. Which indeed goes a long way to explain why MySQL is considered so fast compared to other RDBMSs (relational database management systems). Purists might argue it's because it dosen't qualify as an RDBMS, instead it's just a store of tables with an interpreter that allows SQL style queries. That brings me to another point. Normalisation _doesn't_ remove redundancy from your data! It replaces uncontrolled redundancy in data meant to be informative with controlled redundancy in the form of having the exact primary key of a row in a second table being referenced as a foreign key in a the first table. And the data in the first table refers to or is related to data in the second table. To find related data to the current row in the current table you do a join where the foreign key of the current row equals the primary key of the second. Actually more typically you'd have a join that returns a (psuedo) table consisting of many rows, each with all the columns of the first table and all columns of the second, but only where the foreign key of the row of the first table matches the primary key of the row of the second. There will be just one match at most per row of first table, because each foreign key only has on value, indeed, that's true of any row/column intersection, it's a singular value, AND you can't have more than one row in the same table with the same primary key. But you _can_ have one row in the second table turn up more than once in a join. Think of an address. People can share them. But we wouldn't want to _store_ it multiple times, because maybe we'd like to edit it, let's say a suburb is subdivided or renamed... So maybe we put each distinct address as a row of a table. But normalisation has a cost. Namely that if we have selected a person, we don't have address, so every time we need a join to find it. Which is slower than just printing out a person row with all that extraneous shit already stuffed into it. So often database designers will practice strategic denormalisation. And/or use a 'view', basically a virtual table that resulted from a join. Because join, queries, etc. don't usually return actual new tables, but the results are kind of formatted in a way that resembles a table except you can't typically do queries on it without generating it again. Views remove that restriction.
@daniellambert726
@daniellambert726 2 жыл бұрын
I can't find the .env file in the starter source code. Has it been removed?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
.env files should never be in a Github repository. They are used to store environment variables with values like API keys, database passwords, and other secrets. A .env file should always be added to the .gitignore file's filelist to insure it is not added to a code repository. You will need to create your own .env file for this tutorial. I hope this helps!
@daniellambert726
@daniellambert726 2 жыл бұрын
@@DaveGrayTeachesCode Thank you so much for your fast reply! I'm a total beginner...
@ka8an276
@ka8an276 6 ай бұрын
Professor Severus Snape
@ap7086
@ap7086 Жыл бұрын
In my login system iam building i have a coconut farmer coconut collector and a buyer and after login all three of them should navigate to their respective pages (an update profile page) there is no admin so how to alternate your app to according to my reqitments dave any suggestion will help me a lot
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
I think I would apply user roles - covered earlier in this Node.js series - and you could route based on those.
@ap7086
@ap7086 Жыл бұрын
@@DaveGrayTeachesCode hi dave , can you kindly explain a bit more on this
@methmaaravinda5107
@methmaaravinda5107 Жыл бұрын
hello dev, I wanna know that the way it industry doing things? or your own practise?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
That's like asking "How do people do things?" Of course, they do things in many different ways. So do dev teams. In general, yes, I am doing things like other developers. Will you find that some dev teams in the industry do things differently. Yes, you will. Learn what you can and realize there is never usually only one way to achieve the goal.
@yogishagill8738
@yogishagill8738 2 жыл бұрын
hello sir i am working on a fullstack ecommerce website using react.js node.js mongodb .i am stuck at point of database connect can you help me with that i am using mongoose v6.3.1
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
In this MongoDB series, I show how to connect to the database with Mongoose.
@yogishagill8738
@yogishagill8738 2 жыл бұрын
@@DaveGrayTeachesCode I got the solution after some reasearch thankyou sir
@farouk9253
@farouk9253 2 жыл бұрын
@@yogishagill8738 hey how did u fix it? i seem to be having the same problem where i cannot connect to my database. 'Error: unable to connect to databse:'
@nurlanshukurov3864
@nurlanshukurov3864 4 ай бұрын
(node:6036) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version (Use `node --trace-warnings ...` to show where the warning was created) (node:6036) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version hi, Dave. I got these warnings, how to solve them? Thanks!
@mecklonfernandes5036
@mecklonfernandes5036 3 ай бұрын
Just had the same error, did you solve it?
@nurlanshukurov3864
@nurlanshukurov3864 3 ай бұрын
@@mecklonfernandes5036 delete them, not needed anymore. Can't find any solution, but see new code bases that don't use them anymore.
@mikeysauce393
@mikeysauce393 9 ай бұрын
MongoDB🐍🌮🌮🌮
@exe.m1dn1ght
@exe.m1dn1ght 11 ай бұрын
tf is this man talkin
@Pareshbpatel
@Pareshbpatel 8 ай бұрын
{2023-10-11}
Learn MongoDB in 1 Hour 🍃 (2023)
1:00:00
Bro Code
Рет қаралды 948 М.
Пробую самое сладкое вещество во Вселенной
00:41
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 32 МЛН
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 18 МЛН
tRPC, gRPC, GraphQL or REST: when to use what?
10:46
Software Developer Diaries
Рет қаралды 71 М.
Connecting NodeJS with MongoDB | Mongoose + Express
19:18
Piyush Garg
Рет қаралды 88 М.
Node.js File Upload API with Express Tutorial
35:25
Dave Gray
Рет қаралды 64 М.
Mongoose Crash Course - Beginner Through Advanced
33:36
Web Dev Simplified
Рет қаралды 449 М.
MongoDB + Mongoose + Node.js Crash Course | CRUD and fundamentals of MongoDB
1:09:21
Learn Express Middleware In 14 Minutes
14:48
Web Dev Simplified
Рет қаралды 388 М.
MongoDB Explained in 10 Minutes | SQL vs NoSQL | Jumpstart
11:18