MongoDB and Mongoose | Creating a REST API with Node.js

  Рет қаралды 439,700

Academind

Academind

Күн бұрын

Time to not only handle our data in the endpoints (and then let the data go into the void) but to actually add a database: MongoDB!
Join the full MongoDB course: acad.link/mongodb
Exclusive discount also available for our course: acad.link/nodejs
Dive into the full Node.js REST series: academind.com/...
Check out all our other courses: academind.com/...
----------
MongoDB Docs: www.mongodb.com/
Mongoose Docs: mongoosejs.com/...
Source Code: github.com/aca...
----------
• Go to www.academind.com and subscribe to our newsletter to stay updated and to get exclusive content & discounts
• Follow @maxedapps and @academind_real on Twitter
• Join our Facebook community on / academindchannel
See you in the videos!
----------
Academind is your source for online education in the areas of web development, frontend web development, backend web development, programming, coding and data science! No matter if you are looking for a tutorial, a course, a crash course, an introduction, an online tutorial or any related video, we try our best to offer you the content you are looking for. Our topics include Angular, React, Vue, Html, CSS, JavaScript, TypeScript, Redux, Nuxt.js, RxJs, Bootstrap, Laravel, Node.js, Progressive Web Apps (PWA), Ionic, React Native, Regular Expressions (RegEx), Stencil, Power BI, Amazon Web Services (AWS), Firebase or other topics, make sure to have a look at this channel or at academind.com to find the learning resource of your choice!

Пікірлер: 629
@thierrykas1528
@thierrykas1528 7 ай бұрын
If you're a new folk, remember to use at 24:35 ---Product.deleteOne({ _id: id })--- instead of remove and at 28:52 use ---Product.updateOne({ _id: id }, {$set: updateOps})--- instead of update, Thanks Max!
@sephiroLord
@sephiroLord 4 ай бұрын
Thank you Sir! much appreciated!
@SteveLewis2024
@SteveLewis2024 7 күн бұрын
Annoyingly, I d found this comment after looking at the Mongo forum -_-
@unaisulhadi9102
@unaisulhadi9102 3 жыл бұрын
3 Years later, Still this one is the best Node REST tutorial on Internet. ❤❤❤
@ragunath_br
@ragunath_br 3 ай бұрын
Its still the best one I have seen too.. And its been 6 years now..
@hyojungyu1667
@hyojungyu1667 3 жыл бұрын
For the patch request in 2021, you can simplify the code as below. ;) router.patch('/:id', (req, res, next) => { const id = req.params.id; Product.findByIdAndUpdate(id, { $set: req.body }, { new: true}) .then(result => res.status(200).json(result)) .catch(err => res.status(500).json({ error: err})) })
@izzy7402
@izzy7402 3 жыл бұрын
helpful, thanks man
@matthewrideout426
@matthewrideout426 3 жыл бұрын
great - thanks :)
@ganeshan56
@ganeshan56 2 жыл бұрын
instead of set, we can also use the extend function from lodash package.
@dr.franxx
@dr.franxx 2 жыл бұрын
thank you
@burhanali7449
@burhanali7449 Жыл бұрын
Thanks
@dorukoktay1054
@dorukoktay1054 6 жыл бұрын
Great tutorial Max you are the best!! I used async-await synax instead of then() and catch() functions and it worked. For example; router.patch('/:productId', async (req, res, next) => { const props = req.body; try { const result = await Product.update({_id: req.params.productId}, props).exec(); console.log(result); res.status(200).json(result); } catch (e) { console.log(e); res.status(500).json(e); } });
@5timeslllll
@5timeslllll 6 жыл бұрын
Thanks Max. For PATCH, I have a much better solution: const props = req.body; Product.update({_id: productId}, props); That’s it! It works like a charm, whether one prop has been passed or multiple.
@ruslanuchan8880
@ruslanuchan8880 5 жыл бұрын
Loved this!
@moviejungle1430
@moviejungle1430 5 жыл бұрын
Nice!
@madarauchiha6290
@madarauchiha6290 5 жыл бұрын
thanks :)
@caloriecoin_ceo7847
@caloriecoin_ceo7847 5 жыл бұрын
Thank you!
@fabio4079
@fabio4079 4 жыл бұрын
Explain? I can't make it patch here.
@mikaeledebro1144
@mikaeledebro1144 6 жыл бұрын
Great tutorial Max. Best teacher on YT. Just a small improvement. For the PATCH, I think this is a cleaner solution: const updateOps = {} for (const key of Object.keys(req.body)) { updateOps[key] = req.body[key] } This way you can keep the request simple (same as POST).
@alihasana2009
@alihasana2009 6 жыл бұрын
Thanks Mikeal
@darshu62
@darshu62 6 жыл бұрын
MAX code didnt work for me, but your code did. Thanks Mikael...
6 жыл бұрын
You also can use for ... in to avoid Object.keys(req.body). so the code is: for (const key in req.body) { updateOps[key] = req.body[key]; }
@harsh7809
@harsh7809 4 жыл бұрын
24:26 If you are having problems with delete functionality, try this remove() is depreciated, you should use deleteOne() router.delete('/:productId', (req, res, next) => { id = req.params.productId; Product.deleteOne({ _id: id }) .exec() .then(result => { console.log(); if (result.deletedCount > 0) { res.status(200).json({ message: "Deleted Successfully" }); } else res.status(500).json({ error: "No ID Found" }); }) .catch(error => { res.status(500).json({ error: error }); }); });
@mawalibhai636
@mawalibhai636 3 ай бұрын
Thanks
@MarcosLopez-bs6xr
@MarcosLopez-bs6xr 4 жыл бұрын
This is the only REST tutorial where I don't have to stress over the configuration thank you!
@tonhuu7132
@tonhuu7132 4 жыл бұрын
Very easy to understand and explain in detail. Thanks Max!
@academind
@academind 4 жыл бұрын
Glad it was helpful!
@mikemalone4867
@mikemalone4867 6 жыл бұрын
Fantastic work, sir! I have searched high and low for someone to explain how to write an Endpoint with Node.js without assuming that we know all of the jargon that goes along with it. Most of the time, I see examples with what looks like reserved words only to find out that they are not. I would spend hours trying to find out where the examples obtained the values from that were used in the functions etc. This is clear and easy to understand. Good code is easy to read and easy to write and you are doing just that! Thank you!
@academind
@academind 6 жыл бұрын
Thanks a lot for your wonderful feedback Mike, it really makes me happy to read that the video was understandable and helpful :)
@dusnen
@dusnen 4 жыл бұрын
If you are having problem for PATCH request, use this: router.patch("/:productId", (req, res, next) => { Product.updateOne({ _id: req.params.productId }, { $set: req.body }) .exec() .then(result => { res.status(200).json({ message: "Updated successfully" }); }) .catch(err => { console.log(err); error: err; }); }); it works for me
@gofudgeyourselves9024
@gofudgeyourselves9024 4 жыл бұрын
Thanks a lot man
@zaloaustine
@zaloaustine 4 жыл бұрын
Saved me after lots of hours of research and code re-writing
@tharunrocky14
@tharunrocky14 6 жыл бұрын
Awesome Max! Thanks! Yesterday I purchased your ReactJs course at Udemy, will start with it soon. Thanks for everything.. =)
@hcx1853
@hcx1853 6 жыл бұрын
Tharun Shiv Did the same as well. Looking forward to the course. And your Vue.js course too.
@academind
@academind 6 жыл бұрын
Thank YOU guys for your awesome support! Great to have you on board of the course, I really hope that you will like it :)
@luckystarsakkeer1312
@luckystarsakkeer1312 5 жыл бұрын
@@academind Hi, Max. Can you upload another step by step playlist. How to implement ORM with mySQL into Node Js project. It's my request. :). i'm waiting for your reply, Or refer me some tutorials for this. I'm new to Node Js. I'm working as a Front end developer. Now I started the Back End Development. Your RESTful API tutorial was awesome and very clear. I want to use mysql in my project. Still I couldn't get the perfect tutorial for my problem.
@lilithfirefly3727
@lilithfirefly3727 4 жыл бұрын
really helpful thanks. I saw many other newer videos but this one is the best
@jameswaring6200
@jameswaring6200 4 жыл бұрын
You have a really great way of explaining things!
@Sledno1
@Sledno1 6 жыл бұрын
There is another possible way to delete by id, you can use: Product.findByIdAndRemove(productId) .then(result => { // Send result }) .catch(err => { // Handle error }); This one returns the document as the result. By the way thanks for this course, it has helped me a lot! :)
@Rallek
@Rallek 5 жыл бұрын
Thank you for making such incredible tutorials. You are a great teacher!
@academind
@academind 5 жыл бұрын
So happy to read that Rallek, thank you very much for this awesome feedback!
@nicola123ste
@nicola123ste 4 жыл бұрын
Top teacher in the Internet. I am taking his React course on Udemy too. Can you please add the mySQL version too?
@ificouldfly4874
@ificouldfly4874 5 жыл бұрын
7:58: you need to replace {useMongoClient: true} by { useNewUrlParser: true, useUnifiedTopology: true } + don't forget to restart your nodejs server
@ificouldfly4874
@ificouldfly4874 5 жыл бұрын
@@internet4543 ty Captain Obvious
@sagarkumar0190
@sagarkumar0190 4 жыл бұрын
When I try to connect the mongodb via URL string it is working fine, but if I use + process.env.MONGO_ATLAS_PW + and accessing this environment variable from the nodemon.js file as shown in the video I am getting Error as below : (node:17036) UnhandledPromiseRejectionWarning: MongoError: bad auth Authentication failed. at _authenticateSingleConnection (D: ode-rest-shop ode_modules\mongodb\lib\core\auth\auth_provider.js:46:25) at sendAuthCommand (D: ode-rest-shop ode_modules\mongodb\lib\core\auth\scram.js:215:18) at Connection.messageHandler (D: ode-rest-shop ode_modules\mongodb\lib\core\connection\connect.js:334:5) at Connection.emit (events.js:198:13) at processMessage (D: ode-rest-shop ode_modules\mongodb\lib\core\connection\connection.js:364:10) at TLSSocket. (D: ode-rest-shop ode_modules\mongodb\lib\core\connection\connection.js:533:15) at TLSSocket.emit (events.js:198:13) at addChunk (_stream_readable.js:288:12) at readableAddChunk (_stream_readable.js:269:11) at TLSSocket.Readable.push (_stream_readable.js:224:10) at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) (node:17036) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:17036) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. So if you know why I am getting this help me out. Thanks in advance!! :)
@MrWezra
@MrWezra 4 жыл бұрын
@@sagarkumar0190 Did you get a fix for this?
@gugulothvijaynayak4350
@gugulothvijaynayak4350 4 жыл бұрын
@@sagarkumar0190 How to fix? Did you get any solution? Help me out
@gugulothvijaynayak4350
@gugulothvijaynayak4350 4 жыл бұрын
@@MrWezra Any solution? how to fix it?
@abdullaharz5945
@abdullaharz5945 Жыл бұрын
Such a Helpful tutorial. But two methods are not working (Update and Remove). So I replaced "Update" to "findByIdAndUpdate" and "Remove" to "findOneAndRemove". Then its work correctly. Thank you for this tutorial. ❤
@amilab682
@amilab682 4 жыл бұрын
How to solve this? UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
@MrWezra
@MrWezra 4 жыл бұрын
did you solve this?
@kumarsen88
@kumarsen88 6 жыл бұрын
Having been primarily a Pythonista with some Scala Development experience, I have to admit that node consumes the Functional approach (partial functions, currying, map, filter etc) most effortlessly. Idk how many actually noticed that throughout the tutorial :)
@odorlessflavorless
@odorlessflavorless 4 жыл бұрын
You are amazing Max ! Though you have made a recent video about learning, I definitely would like you share more about learning so that the basics are solidified. Your lectures prove you have a clear grasp on the fundamentals of topics that you teach.
@academind
@academind 4 жыл бұрын
Thank you Ananta, I might indeed release such videos from time to time in the future :)
@codinginflow
@codinginflow 3 жыл бұрын
I noticed that MongoDB adds the ObjectId automatically if you don't pass it
@realdotty5356
@realdotty5356 2 жыл бұрын
Ok
@michaeltrembovler8301
@michaeltrembovler8301 4 жыл бұрын
The best explanation I've only listened to from anyone !!! Many thanks.
@mekonnenhaileslassie5651
@mekonnenhaileslassie5651 4 жыл бұрын
words in the comment can't express what u are doing! But i wanna tell u that u have to proud of your self b/c u are changing life of many people! You are really amusing person!
@ebratz
@ebratz 5 жыл бұрын
at 2019, you can use findOneAndUpdate which is smart enough to understand the parameters it should update on PATCH/PUT. No need to loop ops to filter. Also, needed to use some mongoose options: useNewUrlParser: true, useCreateIndex: true, useFindAndModify: false
@danielblank9917
@danielblank9917 3 жыл бұрын
Your tutorials are great, giving likes for all of them! If I could say one thing, could you disable the documentation popups in vscode as it's a bit distracting and blocks the text
@mavisakal77
@mavisakal77 6 жыл бұрын
Great tutorial but I would suggest Model.findByIdAndRemove(req.params.id).exec().then().catch() and Model.findByIdAndUpdate(req.params.id, req.body, {new: true}).exec().then().catch() for delete and update. Much easier and clean to implement.
@TheMaxik
@TheMaxik 4 жыл бұрын
Man you are incredible. I have trouble understanding things and you explain things so well that I'm advancing on this course very fast. Thanks!!!
@academind
@academind 4 жыл бұрын
Just awesome to read that, thanks a lot for your comment!
@user-zb5jp4ti1d
@user-zb5jp4ti1d 6 жыл бұрын
i have always been struggling with the difference betn schema and model and how they fit together... until now though - key breakthrough for me around the 11:00 mark: "you export the schema wrapped in a model..." As always, thanks so much, Max... You are, in the words of Yuval Harari, a Homo Deus.
@academind
@academind 6 жыл бұрын
That's so awesome to read Ashim, thank you very much for sharing this! Really happy to read that I could help making things clearer for you :)
@israelruas948
@israelruas948 7 ай бұрын
Great, I am using MongoDB online and it is working super well. Thank you
@Bod88
@Bod88 6 жыл бұрын
Your videos have forced me to start finally using modules...and I am grateful for it. T hank you.
@academind
@academind 6 жыл бұрын
So great to read that Bod, thank you for your comment!
@J0pain
@J0pain 6 жыл бұрын
Why the "_id" in the productSchema isn't it there by default ?
@mohsenmadi3590
@mohsenmadi3590 6 жыл бұрын
Actually, adding it gave me an error "TypeError: Undefined type `ObjectID` at `_id`". Removing it worked fine - at least for now.
@marianeppinheiro
@marianeppinheiro 6 жыл бұрын
me too =/
@marianeppinheiro
@marianeppinheiro 6 жыл бұрын
Actually I just fixed it, check out if you are not instanciating the objectID type on the schema. that was my mistake.
@luciusrex
@luciusrex 6 жыл бұрын
use const productSchema = mongoose.Schema({ _id: mongoose.Schema.Types.ObjectId, name: String, price: Number });
@rotrose7531
@rotrose7531 4 жыл бұрын
Thank you very much, possibly best rest api tutorials I can find on youtube.
@brianwahome5789
@brianwahome5789 6 жыл бұрын
Though optional, kindly review the invariant, Should be if (doc.length > 0), not (doc.length >= 0)
@benstuijts5620
@benstuijts5620 6 жыл бұрын
Why not using your error middleware for handling your errors? This will produce less same code... ;-) Great series btw!
@tmacka88
@tmacka88 6 жыл бұрын
How were you getting null returned with a get request when you added a "d" to the end of the ID? I get the error: "Cast to ObjectId failed for value" for everything except when it finds an actual ID in the db. Am I missing something?
@saurabhgupta6691
@saurabhgupta6691 3 жыл бұрын
yes
@qhpfr1
@qhpfr1 6 жыл бұрын
Awesome I am waiting for a lesson on how to security the service(API) secure the API by JWT or etc..... thanks Man
@academind
@academind 6 жыл бұрын
It'll be included in this series, no worries!
@hlrbBrambleX
@hlrbBrambleX 2 жыл бұрын
A better solution on what he did on iterating the req.body in router.patch(): for (const [key, value] of Object.entries(req.body)) { updateOps[key] = value; } with this, you don't need to change the structure of json when sending the request. This tutorial is a gem, I like it...
@chagantisubhash
@chagantisubhash 6 жыл бұрын
I downloaded these videos, kept them in a folder and now using them as a reference. Thanks alot!! I'll for sure buy Angular 6 complete guide course of yours in Udemy.
@academind
@academind 6 жыл бұрын
Awesome! Welcome on board of the Udemy course, too! :-)
@markwonder8168
@markwonder8168 5 жыл бұрын
What's the shortcut to quickly refactor .exec().then().catch() to multiple lines?
@muchvibrant
@muchvibrant 5 жыл бұрын
prettier
@mylastore
@mylastore 5 жыл бұрын
I just purchase your node.js on udemy just because you where born to teach and I am sure I will learn more from that as well as this. Have a question. Is there a reason to create the id on the model? since Mongo generates one automatically anyways.
@luigivampa9780
@luigivampa9780 6 жыл бұрын
Hey Max! I found your course really compelling. Thank you
@academind
@academind 6 жыл бұрын
Thanks a lot for your comment Luigi, happy to read that you liked the course!
@npip99
@npip99 6 жыл бұрын
22:10 Bit of a suggestion for better status code returns, status code 500 should be for an internal error, as stated by postman. Malformed input is supposed to return status code 400 (Bad Request).
@academind
@academind 6 жыл бұрын
Thanks for sharing this improvement, much appreciated!
@jeanpaulgiraldo
@jeanpaulgiraldo 6 жыл бұрын
When I followed the video Mongoose is on version 5.1.1. I was having problems with removing a product using Product.remove({ _id: id }) The error provided by MongoDB said: "Cannot use (or request) retryable writes with limit=0" If anyone else has this problem just replace Product.remove({ _id: id }) with Product.findByIdAndRemove(id) it worked for me
@TheMypencil
@TheMypencil 6 жыл бұрын
Thank you
@김세경-o3i
@김세경-o3i 6 жыл бұрын
Thank you
@joshuaclay1594
@joshuaclay1594 6 жыл бұрын
Thanks so much. Development would be so much easier if there weren't the constant gotchas of changing protocols.
@JuanFVasquez
@JuanFVasquez 6 жыл бұрын
Thanks!! That worked perfectly
@spectrecular9721
@spectrecular9721 6 жыл бұрын
*Product.deleteOne({ _id: id })* worked for me
@khalidebrahim6086
@khalidebrahim6086 9 ай бұрын
Thank you from Egypt 💙
@sarasherif7834
@sarasherif7834 6 жыл бұрын
Great videos in node.js :) I have question, why did you added _id in schem ? I know it generate automatically
@NepalReddyChityala
@NepalReddyChityala 6 жыл бұрын
To match the object property set on product.
@ajaytiwari715
@ajaytiwari715 4 жыл бұрын
24:41: replace remove with deleteOne as remove method is deprecated.
@WatDiggityDawg
@WatDiggityDawg 4 жыл бұрын
to be fair this vid is from 2017
@ajaytiwari715
@ajaytiwari715 4 жыл бұрын
@@WatDiggityDawg yes true, but people are still learning from these videos and they may face difficulty due deprecated functions so like few others who have shared solution for bug or error i also shared..
@codinginflow
@codinginflow 2 жыл бұрын
Tip: In the newer versions of Node you don't have to type --save anymore. It's the default behavior now.
@ngyi3553
@ngyi3553 6 жыл бұрын
What keyboard shortcut do you use to restructure the chain methods?
@amitbhandari8347
@amitbhandari8347 6 жыл бұрын
While deleting, to remove object you need to use array splice function. It will not give you empty [ ]
@tayfoooooor
@tayfoooooor 6 жыл бұрын
Great tutorial, Simple & Quick
@academind
@academind 6 жыл бұрын
Thank you so much for your great feedback Mahmoud!
@zenner24
@zenner24 4 жыл бұрын
if you are using mongoose in April 2020 and get an error while trying to connect, you need to get the connection string in the MongoDb Atlas for Node.js 2.2.12 or later the second argument in the connect function should be: useNewUrlParser: true, useUnifiedTopology: true
@gmfuentes
@gmfuentes 5 жыл бұрын
easiest way on updating data. Product.update({_id:req.params.productId}, {$set: req.body} )
@rajbhoria2406
@rajbhoria2406 5 жыл бұрын
Yes, really simple, thanks
@asdqwe4427
@asdqwe4427 6 жыл бұрын
Your patch method is strange to me. Why would you pass an array of objects to a URL that takes an id? Could you not just use whatever is in the body? I tried it and it seems to work fine for me.
@AbdulMajeedShehzad
@AbdulMajeedShehzad 6 жыл бұрын
Thank you so so much Max! i have learned to create Rest Api from some other channel and it was nice but no one can reach your level! the way you explain each and every thing is very awesome ... a lot of things needed explanation in that course but you explain each and every line in a way that we don't need any more explanations. One thing that i love the most of you is that you reply to each and every comment and this really show your concern with your students this shows that you really care about your every single student and not like many other youtubers who only care for their views! You are the best teacher i ever had! Love from Pakistan Another thing, you mentioned in this lecture that you will teach how to create API with MySql, where is that ? i have searched your channel but could not found it. if you have not created that yet then please create it i badly need that to learn.
@StackMentor
@StackMentor Жыл бұрын
#Academind this is the best tutorial over all this years since you created this playlist most people don't cove the fundamentals and authentication they use some dummy data from routes so far this the best i watched it like 5 times while i was doing node
@DuyTran-ss4lu
@DuyTran-ss4lu 4 жыл бұрын
This man is a legend
@confearsion3778
@confearsion3778 4 жыл бұрын
_id field is not required in 2019 I guess, plz tell me is it true?
@mowliprakash9231
@mowliprakash9231 4 жыл бұрын
i got sn error that SyntaxError: Unexpected token in JSON at position 14 at JSON.parse ()
@esericsu
@esericsu 4 жыл бұрын
wow this is really really good. Please keep making more
@jakubrpawlowski
@jakubrpawlowski 6 жыл бұрын
Great video as always Max! Thank you again!
@academind
@academind 6 жыл бұрын
Thanks so much Jakub!
@Sun1ive
@Sun1ive 6 жыл бұрын
Thank you very much for your lessons Max. Really appreciate it!
@academind
@academind 6 жыл бұрын
Thank YOU for your comment, so happy to read that you like the videos!
@phillippham8454
@phillippham8454 5 жыл бұрын
What is the hotkey he is using to reformat the .exec.then.catch chain over multiple lines?
@hotwings9382
@hotwings9382 6 ай бұрын
for the patch request at 34:00 I changed update to updateOne and it worked
@ilearncode7365
@ilearncode7365 4 жыл бұрын
Please add the mySQL version!
@codyuhi8010
@codyuhi8010 4 жыл бұрын
I got an error that said "UnhandledPromiseRejectionWarning: MongoParseError: URI does not have hostname, domain name and tld" . The way I fixed this is by replacing the special characters in my password with the URI encoded equivalents of them (so like %23, %21, etc.). Posting this here in case anyone else runs into the warnings and wants them to go away. :)
@deepalijain6349
@deepalijain6349 4 жыл бұрын
Thankyou that helped me alot👍
@mateusloubach
@mateusloubach 5 жыл бұрын
Max, I have finished this project and wanted to set it up with a front-end webpage (single page) on Heroku. However, Heroku doesn't provide an add-on (other than MongoDBs newly acquired mLab add-on for databasing) and MongoDB doesn't provide this service. I was wondering HOW can we set it up on the front-end webpage in order to use the database created with this course. Thank you so much for sharing such knowledge and I've got to say, this has been THE BEST teaching by far I have EVER had. will definitely keep learning with you! Cheers!
@prashantchaudhari6183
@prashantchaudhari6183 6 жыл бұрын
I think instead of using promises, async/await would be great. Yeah i know async/await are basically promises but it would help in writing cleaner code.
@adrianlineweaver4725
@adrianlineweaver4725 5 жыл бұрын
for patch you could also use Product.update({_id: id}, { $set: {...req.body} })
@zumatse
@zumatse 6 жыл бұрын
Hi what is VSC shortcut to change inline exec().then().catch() to every function in new line?
@academind
@academind 6 жыл бұрын
I don't know what the default was but search the keybindings for "code format" or just "format"
@hamzaayech5966
@hamzaayech5966 6 жыл бұрын
You are so good at teaching people, please keep going ♥
@academind
@academind 6 жыл бұрын
It's really great to read that you like my teaching style, I'll try my best to keep it going Hamza!
@dmitry4638
@dmitry4638 4 жыл бұрын
By any reason the patch request doesn't work with this body: [ {"propName": "name", "price": "15000000"} ] it says: { "error": { "message": "req.body is not iterable" } }
@rhandect
@rhandect 4 жыл бұрын
Thank you so much, you have helped guide me in the right direction for my project :)
@mihaidraghicescu1020
@mihaidraghicescu1020 6 жыл бұрын
Great series! Will you make a short tutorial with REST API and MYSQL ?
@academind
@academind 6 жыл бұрын
Thanks so much, I'm glad you're liking it! I might add MySQL in the future, got no concrete plans on that right now though.
@marcelonogueira8544
@marcelonogueira8544 6 жыл бұрын
kzbin.info/aero/PLFJmwzuHdBRTBbkyH0gATtDhj6ikOIkMy
@nanminkone
@nanminkone 5 жыл бұрын
Nice Nice Nice...My project saw life because of this video
@HishamAbiFarah
@HishamAbiFarah 6 жыл бұрын
If you're getting errors connecting to atlas mongo db simply change to mlab , create account and use connectinstring in your app like this: const uri = "ConnectingString from mlab''; mongoose.connect(uri ,{ useNewUrlParser: true }); process.on('unhandledRejection', (reason, promise) => { console.log('Unhandled Rejection at:::', reason.stack || reason) })
@Angela13111
@Angela13111 3 жыл бұрын
Hi, Anyone that will get this error: (node:2096) UnhandledPromiseRejectionWarning: MongoParseError: option usemongoclient is not supported at Object.parseOptions just delete the line: usemongoclient = true; in the apps.js file. took me 3 days to figure it out hope it will assist someone else.
@GolemShadowsun
@GolemShadowsun 2 жыл бұрын
You saved me just HOURS of debugging.
@alevsoft
@alevsoft 4 жыл бұрын
Awesome tut! Thank you :)
@alind9947
@alind9947 5 жыл бұрын
What s the advantage of using .then and .catch at 14:10 when you save a product instead of a callback? You basically do the same thing you would do with a callback as in getting the result and handling the error only that with .then and .catch you even type more lines of code.
@declanpossnett2481
@declanpossnett2481 6 жыл бұрын
A better way to handle the PATCH is to do the following: Object.keys(req.body).forEach(key => { updateOps[key] = req.body[key]; }); This will allow the API user to send a normal JSON object for example: { "name": "Harry Potter 1000" }
@SARAVANAKUMARPS
@SARAVANAKUMARPS 6 жыл бұрын
Though I subscribed to this channel and enabled notification, I come daily to check whether the next video has arrived or not! Thanks for the awesome series and you are the best tutor/mentor whatever!. Is there any plan on teaching complete Node Js and JWT.
@academind
@academind 6 жыл бұрын
Thank YOU for your amazing feedback, I'm happy to hear you're liking the content on this channel! I will also show how to implement Authentication with JWT in this series, yes
@agung_laksana
@agung_laksana 5 жыл бұрын
max, please create mongoose course in detail :D
@abdelrahman2348
@abdelrahman2348 6 жыл бұрын
Danke Max , why I get Cannot read property 'name' of undefined when I try to post on postman
@pasindu-sandaruwan-silva
@pasindu-sandaruwan-silva 5 жыл бұрын
I know this is a late reply. But I will post a solution for this . The same happened to me too. This happened to me because the app could't locate the Product.js( model ) . Check whether that you have imported the Product properly.
@gabrieljoshuapaet2572
@gabrieljoshuapaet2572 6 жыл бұрын
First of all really great tutorials from you Max! Will you be creating a series dedicated to mongodb and mongoose?
@academind
@academind 6 жыл бұрын
Thanks so much, happy to hear you liked it! Such a series is definitely possible, yes :)
@daniell2774
@daniell2774 4 жыл бұрын
At the 28:08 time stamp; there's if(docs.length >= 0) { do stuff }. To my understanding that will always be true if there's no entries in the products. Shouldn't it be if(docs.length >= 1) { there's at least one or more entry -> show entry/entries.} ELSE { show the 404 error along with the message } Please correct me if I'm wrong!
@balporsugu7198
@balporsugu7198 4 жыл бұрын
yeah i agree with you. he missed it because as he mentioned he does not consider that situation as an error.
@rajatdhoot5936
@rajatdhoot5936 6 жыл бұрын
Awesome tutorial Really great help to understand and build Rest Api from scratch
@academind
@academind 6 жыл бұрын
Thanks so much, great to hear you enjoyed it Rajat!
@MrScrosb
@MrScrosb 6 жыл бұрын
Hey Max, I think the free tier for Mongo Atlas is no longer able to use the post request on this database. I keep getting a not authorized on admin to execute command.
@MrScrosb
@MrScrosb 6 жыл бұрын
use mlab.com instead of mongoDB cloud atlas to execute commands.
@a99912334
@a99912334 6 жыл бұрын
Hello everyone, for those who encounter the problem with auth failed. U can add dotenv in your project, then create a .env file to set the variable like mongoose.json in the video. Then do this code ' require(dotenv). config()' which let dotenv create local env variable. By doing these, you can successfully use MONGO_ATLAS_PW.
@stankurek3617
@stankurek3617 6 жыл бұрын
works! big thanks!
@techdailyafrica
@techdailyafrica 3 жыл бұрын
I learnt flutter with Max, Now we're here in MongoDB
@HAL-9000-
@HAL-9000- 4 жыл бұрын
diese Videos sind super, danke!
@starboy5765
@starboy5765 6 жыл бұрын
Awesome tutorial Max! But Unfortunately got stuck when sending this POST request at 15:45, it shows me an error. "error": { "message": "Product is not a constructor" }
@cavinalbertbelga5090
@cavinalbertbelga5090 6 жыл бұрын
Same, did you find a fix?
@captainzerodegree8162
@captainzerodegree8162 5 жыл бұрын
You probably missing module export from product model
@santiagorestrepo4874
@santiagorestrepo4874 4 жыл бұрын
make sure your export sentence in product.js is module.exports = mongoose.model('Product', productSchema) instead of module.export = mongoose.model('Product', productSchema)
@yatashdeepsharma203
@yatashdeepsharma203 6 жыл бұрын
awesome tutorial mere bhai ... hats off u
@HACKTECH
@HACKTECH 6 жыл бұрын
Can't we add directly an callback as a second argument in findById() or use exec() and attach it after findByID() because you used promise Approach using then()...so is it necessary to use it?
@k.alipardhan6957
@k.alipardhan6957 6 жыл бұрын
your naming might follow convention buts its had for us to understand product vs Product ( because we can see all the code at once)
@harrydjalimun9272
@harrydjalimun9272 5 жыл бұрын
Hi, i’ve some error :Connection Error { Error: queryTxt ETIMEOUT},i’ve try to delete olde cluster still have kind of error, pls somebody help me, thx
@eshikarya
@eshikarya 4 жыл бұрын
In productSchema lets suppose I have address instead of price and an address contains both alphabets and numbers what should I use then? instead of "price : Integer" -> "address : ????"
@rabiashah9686
@rabiashah9686 6 жыл бұрын
I love you for this awesome explanation!! hats off to you! you saved my day!!
@academind
@academind 6 жыл бұрын
So amazing to hear that, thank you so much Rabia!
@smsoniinfosoft-1383
@smsoniinfosoft-1383 3 жыл бұрын
I am using node14+ version and angular 11. I am facing some issue between connectivity of them. Sometimes it will display such as "required is not found " and sometimes Display " out of module". How can I solve this issue? Please let me know.
@alpsenel9196
@alpsenel9196 4 жыл бұрын
You helped a lot !
Mongoose Validation | Creating a REST API with Node.js
18:33
Academind
Рет қаралды 140 М.
Managing Orders with Mongoose | Creating a REST API with Node.js
22:05
Or is Harriet Quinn good? #cosplay#joker #Harriet Quinn
00:20
佐助与鸣人
Рет қаралды 57 МЛН
The CUTEST flower girl on YouTube (2019-2024)
00:10
Hungry FAM
Рет қаралды 51 МЛН
when you have plan B 😂
00:11
Andrey Grechka
Рет қаралды 62 МЛН
Node.js Crash Course
2:06:35
Traversy Media
Рет қаралды 177 М.
Uploading an Image | Creating a REST API with Node.js
21:34
Academind
Рет қаралды 458 М.
Connecting NodeJS with MongoDB | Mongoose + Express
19:18
Piyush Garg
Рет қаралды 121 М.
How to build a REST API with Node js & Express
58:40
Programming with Mosh
Рет қаралды 1,7 МЛН
You might not need useEffect() ...
21:45
Academind
Рет қаралды 160 М.
Mongoose Crash Course - Beginner Through Advanced
33:36
Web Dev Simplified
Рет қаралды 468 М.
Good APIs Vs Bad APIs: 7 Tips for API Design
5:48
ByteByteGo
Рет қаралды 235 М.
Or is Harriet Quinn good? #cosplay#joker #Harriet Quinn
00:20
佐助与鸣人
Рет қаралды 57 МЛН