Nest.js with MongoDB - Complete Example
Вставка
- Опубліковано 3 лип 2019
- Connect your NestJS app to a MongoDB server and learn how to create, read, update and delete (CRUD) data.
Join the full "MongoDB - The Complete Developer's Guide" course: acad.link/mongodb
Exclusive discount also available for my "Node.js - The Complete Guide" course: acad.link/nodejs
Check out all our other courses: academind.com/learn/our-courses
----------
Watch the first part: academind.com/learn/node-js/n...
Starting Code: github.com/academind/nestjs-i...
Finished Code: github.com/academind/nestjs-i...
MongoDB Introduction: academind.com/learn/mongodb/c...
SQL vs NoSQL: academind.com/learn/web-dev/s...
----------
• 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
• Follow @academind_real on Instagram: / academind_real
• 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! - Наука та технологія
Excellent as always Max. Not a waisted syllable. Dilligent preparation. Your commitment to researching and using best practices on every level is greatly appreciated. People: if you haven't taken any of Max's Udemy courses I highly recommend them. There are always sales and Max often includes a discount link in these free vids. I don't think I've paid more than $12.
Thank you for this great course and please keep adding more NestJS courses!
Great one! I always find something new while watching your tutorials, And the way you present is precious! Thanks Max.
Thanks Max! You always post top-notch quality, both on video and the content.
You're my favorite instructor on Udemy. I'm in most of your Udemy courses including MongoDB & NodeJS. You make the subjects easy to understand. Thank you!!
Thanks for this wonderful feedback and your great support Kerry!
I know Im pretty randomly asking but do anybody know a good website to watch new series online ?
@Dalton Jameson Try flixzone. You can find it by googling :)
Thanks, both the videos w.r.t NestJs were quite useful. It helped me a lot to know about NestJs framework and become hands on very easily.
I am watching it after 3 years. you are always my favorite.
Thank you for this minicourse. NestJS is a super cool addition for a project.
Awesome tutorial, glad you made this one to show us how to deal with non-sql engines. Pretty much what developers needed besides the great documentation at NestJS page. However, I know there is other way of using MongoDB on our NestJS project, and that is TypeOrm. Would be great if you can show us the same approach in another tutorial.
CHEERS!
Excellent tutorial sir, I really like your coding practices. Clean and professional
Thank you very much for this further, excellent, free course.
You doing great.
Absolutely amazing tutorial, like always. Excelent job. Thank YOU.
Max you are my best instructor forever..
Your research and teaching efforts for everyone both are begginer or professional and specifically your interaction with student joyful to learn something new with interesting and your theoretical logic for explanations make me easier to understand.
Thank you so much!
Thanks for the clean & clear tutorial, helps a lot..🙏
Thanks Max for the amazing tutorial and nice explanation of each and every concept crystal clear.
Thank you Max, this is what I'm looking for 👍👍👍👍
Hello, Max. Thank you for your work! It's a great stuff and useful much. Once you've asked about what would we like you make a course about? Well, I'm sure that your audience is mostly full stack developers. And as we all have a desire to grow we'd like to be aware of all aspects of development and delivery features to the customers, well at least most of them. I think devops is very interesting topic we all are interested in, especially Kubernetes. It would be great if you make a complete course about it. One more thanks for your videos.
Nice video, much appreciation to you Max for sharing with us! You always level us up!
Thank you :)
Very helpful guide!
You are a true professional!
Hey Max you rock while teaching
Wonderful instructor 💯
infact I was looking for nestjs combo of mongodb
Amazing tutorial ever about Nestjs, I am glad for this. Thanks for everything
Thank you. great series learned a lot.
Excellent Contribution. Thank you.
There is a critical gap here that I don't understand how it is not shown/happening in your video - the Product class actually has to be an interface that extends "mongoose.Documet", otherwise you get a red error in the service ctor underlining because "Type 'Product' does not satisfy the constraint 'Document'".
Why it doesn’t it reproduce here?
awesome, thanks more NestJS!
So you're from München. Excellent tutorial, as always. Much love from your Belgian neighbours (:
Incredible video, thanks for all !
Fantastic primer, Maximilian! Thanks a lot! I learned a lot about mongoose. Do you think you could make yet another video about working with relations? Say, products assigned to Categories. Would you make categories a separate module in Nest app?
Thanks man I always learn with your courses!
Awesome to read that Hosni, thank you for your comment!
Thank you very much. Your video helped me a lot.
Best wishes
Just for anyone else running into this problem with newer versions of mongoose, the Product interface in product.model.ts has to extend the Document interface from mongoose.
So instead of:
export interface Product
You'll need to put:
export interface Product extends mongoose.Document
U saved me of lot of google searching. BIG THANKS!
thanks a lot man legit helped
Damn i've been scrambling here for hours, wondering what I have missed on the tutorial. Thank you so much!
Got the same issue, resolved. Big Thanks.
Thanks!!!!!
Thanks a lot, definitely the best intro with github source.Would be great to have a NestJS Complete Guide too, including maybea little side note on NestJS/Firebase too.
Thank you, got no plans regarding a Complete Guide on NestJS at the moment though.
I was hoping this video. Thank you Max
Hi Max, Can you answer the below questions?
When we perform CRUD operation on the database, I am a bit confused about managing the data in the application.
Currently, What I do is, when I fetched a list of data from the database I stored in the memory in the list and when I want to add new data, first I saved the data in the database if the saving was successful then add to my memory list (which is the same list that I have when I have fetched the data) same follows for updating and deleting a data.
Is this a correct way to do? or I need to do another way around which is fetching (querying the database) the data from the database every time when I add, update and delete a data. Which is one is an optimal solution?
babbal tutorial yrr thikai xa.thanks from year 2021.This video dosent knows what 2020 is bringing home hahah.lol
Again amazing course.
Thanks Max. Amazing tutorial. It would be great if you can add another video on using Swagger and JEST to test the NEST JS application.
Thanks a lot max!! your a hero!
Thank you so much sir.
Some critical feedback: Whenever you complete a task, show it running or atleast test it to make sure you have done it properly. Rather than completing task 'a' and moving to task 'b' only to find task 'a' not working when you completed task 'b', run task 'a' as soon sa you have finished it and are moving to the next big topic :)
[Below is an example, no need to read if you get my point]
When you were connecting to the mongodb 8 mins into the video, it was only at 18:34 you realized there was a problem with the connection. This makes the learning process a bit bumpier than usual. And may bring confusion to others. Thank you :)
that was very helpful...
thank you
THANK YOU VERY MUCH FOR YOUR KNOWLEDGE
Excellent, thank you for amazing work and clear explanations!
were you able to connect with the cloudmongodb cluster?
NestJs course would be great
Not planned in the near future, sorry :/
@@academind U_U
using CQRS pattern and even better if in nx workspace together with angular :D
Thank you for this video.
This is great! Good stuff to practice full stack development.
Happy to read that Cha, thanks a lot!
Thank You Max!!
Thanks Max for this great session. I have one question - If mongoose provides id of the product as product.id (without underscore), why doesn't it return the product with id instead of _id? This would have saved the transform/map?
You maniac, giving this a watch now.
This 5 stars tutorial needs a continuity with one to many relationships using mongoose. I would glady pay for this.
Thank you Maximillian! :)
Please make a bonus deployment video Max. Maybe on Heroku, that will be great.
Thanks for all these great tutorials
Thanks mr. MAX!
thanks for the tutorial
Very very useful actually in the middle 2022 as well
awesome, thank you so much!
This is awesome!
Thank you verymuch!!
Thank you so much!
thanks for this!
Is good practice map result to dto when your query return only some of fields of the document or from many collections? For example when we use aggregate
thanks a lot dude!
AWESOME VIDEO
Great Tutorial Max. Now you must add NestJs + MongoDB + Socket.IO and will be the nice tut. again! Thx!
Got this issue in product service file on constructor line. "Type 'Product' does not satisfy the constraint 'Document'." Please help me out @Academind
at 20:58 how it's returning result.id? when the mongo/mongoose field name is _id. what I'm missing?
Today I knew about netjs..I think its great for Angular Dev like me..
hi Max, it's 2021 and I just following your nestjs tutorial. When I install the @nestjs/mongoose and mongoose it's fine, but when I change the app.module.ts to connect my mongodb, it's showing an error
/home/frans.yosua/Documents/Kerjaan/Project/nestjs-intro/node_modules/mongodb-connection-string-url/node_modules/whatwg-url/dist/encoding.js:2
const utf8Encoder = new TextEncoder();
^
ReferenceError: TextEncoder is not defined
what do I miss?
Excelente!!!
Thank You Sir
i don't understand, I keep getting a connection error when trying to connect to mongodb atlas, with mongoosemodule. It says the uri is undefined, however I am providing the string directly and not with a .env
Hey Max, how are you doing? are you offering or do you have any plan about a nestjs course?
thx
Thanks max, I LOVE NestJS. for me it makes everything easier and more organized :D
Can you please add a course about passport.js to use in our apps? :D
Does the interface you show for the "Product" at 15:00 need to extend the Document interface from Mongoose?
I get an error when trying to use it as the Model type in the service file if I don't include the "extends Document" when defining the interface.
EDIT: I think it's related to the @types/mongoose npm package
Found an answer here: github.com/DefinitelyTyped/DefinitelyTyped/issues/33824#issuecomment-609642686
How do we map dto to mongo schema? If the naming conventions are different. For eg: Spring framework provides this library. "mongodb.core.mapping.Field". Is there anything in Nest JS?
@academind Ssems like there is a newer implementation of nestjs and mongoose. Like using decorators such as @Prop. Do you have that video? Please let us know.
Max always the best
thank you max a great beginning to nest with mongoose but is it possible to connect to a angular application to post get update delete data, mean need a video on angular + nest with mongoose
Hi Max. What about Adonis? Have you used or tried? Thanks.
Thanks Max, as always great video.
Somethings to point out:
- as you know, when you choose to work promises with async/wait sintaxe, you should warp inside try/catch.
- in methods like update / insert or delete, you should return at least the status code of 201.
- why not to use TypeOrm ?
And to finalize, as soon as possible bring a video abou loopback 4. Thanks ;)
TypeORM is for SQL databases .
all those things nestjs does for you. and I think thats beautiful.
@daksh sagar You can use typeOrm with mongodb. But you are right that the advantages of typeorm can be better exploited with sql databases.
@@dakshsagar2839 TypeOrm, it is not only to SQL type DB, also it works with No SQL DB.
links:
docs.nestjs.com/techniques/database
typeorm.io/#/mongodb
waiting to buy that nest js full course
No plans to create such a course in the near future, sorry.
How can I move all configs (database, host, port, ..) to a env file?
Again amazing 10x max
This is fine contintue of previous tutorial, only thing is that, I tried to keep old version as possible with node version 10 LTS, mongoose@5 and @nestjs/mongoose@6 and @types/mongoose, but after update product script gets error . In my situaton I removed @types/mongoose and updated to mongoose@5.13.14 and @nestjs/mongoose@7.2.4.
It would be if you release where you build an authentication api with jwt tokens using nestjs and mongogdb. Thanks for this and the previous videos. Your explanations are always awesome and easy. Still waiting for your nestjs course on udemy as i already have done your nodejs course from udemy in the past.
It would be great if you could expand this tutorial with nested documents, and some of the best approaches (embedded vs reference)
44:25 There is no "result.n" propertiy for delete operation anymore. It returns deletedCount property. So if case should be like this : if(result.deletedCount ===0)
Thanks
Great video!
I have a question:
If you want to add functions to the model like a function that returns a string of firstname + lastname. How you are doing it and exposes this?
thanks Alon
You can create a mongoose virtual and then add it to the interface.
mongoosejs.com/docs/guide.html#virtuals
amazing
Hi Max,
This looks so cool...What is the future of nest.js if someone planning to learn. I have already expertise in Angular + .net.
I am thinking to learn Node.js(MEAN Stack).
Hi Max, your courses simply excellent. Ref: npm install --save mongoose @nestjs/mongoose.
Mr max ! Could you explain about Angular error "ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked" ? I already read the article but i still dont quite understand. Please help if you have some free time ! Thank you so much mr max ! it means a lot ^ ^
At 36:50 I ran into a Problem. In the Project im working on we use shared entities and the frontend guys don't want to deal with mongoose imports obviously. I worked around this by simply removing the returntype from the findProductById-Method. No @types/mongoose needed.
Hi..Great course..i had a small doubt.. How to implement cucstom id using mongodb in nestjs?
could you also explain how to unit test this product service?
Hi, I have one doubt. How mongodb created collection (table Name) name "Products" ? Where are we defining in code base ?
Inside product.module model it is defined
If you're starting from ground, you end up in lot's of issues with VSCode, TypeScript and thus. Return types missing, not compiling without return types... Had similar challenges with the first part of the course, but that was easier to fix, but this is harder if you're new to the topic :-( Perhaps because of changes in nest.js and mongoose? I downloaded the sources and started with them now, and they seem to work, however except the dependencies, my code is identical (up to minute 18:40).
Do you have any vedio on nestjs mongodb user authentication using jwt token
Why do you return Promise in service and then you use in controller async func to get Promise again. You can just return promise. Nest will resolve it.
Could you provide an update to the video based on the new decorators that are suggested in nestJS document like @Schema(), @Prop()? That will be very helpful
bumping into your comment made my life a lot easier :)
I'm not sure how the 'products' collection got created in Mongo DB. Database name was mentioned in the config but not collection name