@@hamedbahram Thanks for the reply:). I just started learning, so I was wondering if the two codes are doing things differently. Also thank you for the video. It's super helpful!
@@EnnBlack the only difference is that I'm awaiting the init function, whereas if you just call it directly, you can't await it. Other than that it'd be the same.
Thank you for the video. 6:55 singletoe pattern is used to share the existing instance of connection for better performance but why is that not used in production then?
9 minutes in but I was wondering , once you made that connect to DB clientPromise do you need to import it wherever you are doing db actions? is there no way to import it in one place and have it run only once? I have multiple next api routes so I was wondering if there is a way to not call for the connect to db function for each CRUD function.
Hey ! Thanks for your videos on nextjs 13 ! I really appreciate it ! There is mistake in the api folder. You're returning a 425 status code. I think it's a 405 status code instead. Keep going, cheers from France !
You're welcome. You can use Prisma, which is a type-safe ORM, you can use this quick start guide to set it up: www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/mongodb-typescript-mongodb
Hi, I just found this video while starting to work with nextjs and mongodb together. I've put everything according to the video including the MONGODB_URI string, and all the code is the same down to the letter, but I keep getting a certificate validation failed error no matter what I do. I'm working with nextjs 13. Do you perhaps know why that would be? Thanks! love your videos btw super easy to follow and clear :D
@@spencersnygg6966 It would go at the end of your connection string, where I put DATABASE in the example below: mongodb+srv://:@your.cluster.mongodb.net/DATABASE?retryWrites=true&w=majority
Another awesome next13 video! Question what if I wanted to do a grid display and wrap each movie edit / delete button? For example, Robin Hood Go West JAWS It is my understanding you would need to add a "use client" component to add the and functionality?
That's right, to add any interactivity to your components, you need react hooks which are only available in client components denoted with the 'use client' directive.
After further research I believe this is the correct method. Storing on global has other implications like potential memory leaks or namespace colliding but in this case you handle both of those well. Using global is fine for this case, thanks.@@hamedbahram
It is not safe for production, global is meant to be used only for development, I am currently looking for a safe and efficient way to handle production myself.
@@TheProOfficial Yes global is meant to prevent recreating the conenciton during Hot Module Reload (HMR) in development. Please do share if you found a soloution for connection pooling in produdction.
@@TheProOfficial Clarification here... I am storing the connection in global on my nextJS server side. So client never sees this. This should be safe for production.
That's a good question! That's one of the problems with serverless functions, you can close it once you're done processing the request, or keep it alive to reduce the response time, which'll then exhausts your connection pool. You can use Prisma connection pooling to avoid that problem or query your db over HTTP.
Awesome content. I have a request to you if possible. Can you do a tutorial using the new NextJS 13 with i18n like next-translate or something similar?
man ur content is life saving , keep teaching us sensei
My pleasure Elouali! I'm glad you found it helpful.
love your camera set up
Appreciate that!
first time, i join in nextjs, so i like the your lecture ~ it's very nice~ it's getting ability up to me
Welcome to NextJs, glad you're learning something.
That part you cut just to speed up the process was very important :(
Which part is that?
Wonderful video, can you please put the code snippets at a place where we can see them in detail? Once again thank you!
Sure thing!
Intuitive content. Appreciate that 👍
Thanks Milad!
in 9:20, why do you need to wrap init() in an async arrow function, but not just call init() directly?
I guess you can call it directly as well 🙂
@@hamedbahram Thanks for the reply:). I just started learning, so I was wondering if the two codes are doing things differently.
Also thank you for the video. It's super helpful!
@@EnnBlack the only difference is that I'm awaiting the init function, whereas if you just call it directly, you can't await it. Other than that it'd be the same.
Thank you for the video. 6:55 singletoe pattern is used to share the existing instance of connection for better performance but why is that not used in production then?
Good question! The pattern in development is to prevent hot module reload from creating multiple connections.
Awesome content bro. Your speaking is so awli 😅.
Damet garm 👌🏻.
Thank you 😁
You saved me thanks, appreciate your hard work.
Glad to hear that!
9 minutes in but I was wondering , once you made that connect to DB clientPromise do you need to import it wherever you are doing db actions? is there no way to import it in one place and have it run only once? I have multiple next api routes so I was wondering if there is a way to not call for the connect to db function for each CRUD function.
good question, we're sharing the connection and only recreating it if it doesn't exist. reference the docs for any update on mongo.
به ارور خورده بودم یهو دیدم لهجه تون فارسیه :))))) خیلی بامزه بود این اتفاق
Lahjaro nemishe karish kard 😅
Thanks for the help! I like the way you teach.
Glad to hear that!
Hi, thanks for the video, can you put out a video of the deployment? Much appreciated.
Sure, will have that in mind. What do you wish to see in deployment?
@@hamedbahram Thank you. I would like to see mongdb in the deployment and it would be nice to see how to use cdn.
@@bibooo7507 I use mongodb atlas which is hosted service, but I'll have that in mind for a future video. Can you expand on what you mean by using cdn?
@@hamedbahram
@@hamedbahram Well, nothing to do with cdn. I'm just emmm messed up in the head and looking forward to your mongdb video
مرسی بابت ویدیوت و تایمی ک گذاشتی خیلی ممنونت میشدیم کد هم میزاشتی واسمون مچکر
Eraadatmand! You can check out the code for this video → ua-cam.com/video/qAgwDGCrzgE/v-deo.html
Hey ! Thanks for your videos on nextjs 13 ! I really appreciate it !
There is mistake in the api folder. You're returning a 425 status code. I think it's a 405 status code instead.
Keep going, cheers from France !
Hey Flo! welcome to the channel. That's right, it should be 405 instead, thanks.
Thanks for this great video. What if we want to implement models and use them instead of "months" or populate fields?
You're welcome. You can use Prisma, which is a type-safe ORM, you can use this quick start guide to set it up: www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/mongodb-typescript-mongodb
@@hamedbahram thanks for your fast answer 🙌
@@Vittokm Anytime!
awesome video! please upload the mongodb video soon. Thanks
Welcome to the channel Renzo. That's coming soon.
Thank you for the video! Do you have the code in Github available?
Unfortunately not! What parts do you need a reference for? maybe I can help here ;)
Thank you hamid, great video
My pleasure! welcome to the channel.
Hi, I just found this video while starting to work with nextjs and mongodb together. I've put everything according to the video including the MONGODB_URI string, and all the code is the same down to the letter, but I keep getting a certificate validation failed error no matter what I do. I'm working with nextjs 13. Do you perhaps know why that would be? Thanks! love your videos btw super easy to follow and clear :D
Glad you found the videos helpful. Can you tell me more about the error?
How did you fetch the data not specifying the db name? It didn't work for me until I specified the db name `db = await client.db("sample_mflix");`.
The db name can be in your connection string (MONGO_URI) you set in your `.env`
@@hamedbahram How? where do you put it exactly?
@@spencersnygg6966 It would go at the end of your connection string, where I put DATABASE in the example below:
mongodb+srv://:@your.cluster.mongodb.net/DATABASE?retryWrites=true&w=majority
Another awesome next13 video!
Question what if I wanted to do a grid display and wrap each movie edit / delete button? For example,
Robin Hood
Go West
JAWS
It is my understanding you would need to add a "use client" component to add the and functionality?
That's right, to add any interactivity to your components, you need react hooks which are only available in client components denoted with the 'use client' directive.
is storing a db connection on global safe for production!?
That's a good question! This is the recommended way from the official docs. I'm not sure if and how it'd be unsafe to set a global.
After further research I believe this is the correct method. Storing on global has other implications like potential memory leaks or namespace colliding but in this case you handle both of those well. Using global is fine for this case, thanks.@@hamedbahram
It is not safe for production, global is meant to be used only for development, I am currently looking for a safe and efficient way to handle production myself.
@@TheProOfficial Yes global is meant to prevent recreating the conenciton during Hot Module Reload (HMR) in development. Please do share if you found a soloution for connection pooling in produdction.
@@TheProOfficial Clarification here... I am storing the connection in global on my nextJS server side. So client never sees this. This should be safe for production.
Noob question, but when do you close the database connection?
That's a good question! That's one of the problems with serverless functions, you can close it once you're done processing the request, or keep it alive to reduce the response time, which'll then exhausts your connection pool. You can use Prisma connection pooling to avoid that problem or query your db over HTTP.
What font you used in this video??
I think its Operator Mono.
Can I connect nextjs to mongo compass locally
You can connect NextJs to a mongo server running on your local machine. MongoDB compass however is just an interface (GUI) to interact with your DBs.
مرسی سلطان عالی بود
Mokhlesim Mojtaba jan
Hi There, why did you not use the api routes in the "App" folder?
Hey! the api routes (route handlers) in the `app` folder wasn't introduced at the time of recording.
Awesome content. I have a request to you if possible. Can you do a tutorial using the new NextJS 13 with i18n like next-translate or something similar?
Thanks, Henrique, and welcome to the channel. Interesting topic, I'll definitely have that in mind for future videos.
@@hamedbahram I'm asking that, because its a thing all need (non native english persons) and with NextJS13 with App folder is kinda weird to implement
@@h.fernandes yes of course, I'll definitely look into it.
you forgot to show env file
🧐
Sorry! It would be the MongoDB URL.
thanks
You're welcome!
font size too much small.
Thanks for the feedback, I've tried to make it bigger in later videos.
thanks 🫡🫡
My pleasure 🫡