How to use Mongoose with Next.js for MongoDB | Explained with simple project

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024
  • Hello, my friends and fellow developers!
    In this video, we cover how you can set up Mongoose with Next.js to connect your MongoDB database. We'll also build a project!
    Let me know in the comments below if you want more MongoDB and Next.js videos or any other videos.
    GitHub Repository: github.com/max...
    🧾 Article: blog.usmans.me...
    Other Tutorials:
    ⚛️ React and Material UI Todo App: bit.ly/reactma...
    🟨 Other JavaScript videos: bit.ly/jstutor...
    📘 Visual Studio Code videos: bit.ly/vscodevids
    🔋 Build a Battery App in JS: • 🔋 Build a Battery Info...
    Connect 🔗 :
    Twitter: / maxprogramming1
    Facebook: / max-programming-103081...
    Github: github.com/max...
    🎥 Gear I use:
    🎤 Mic: amzn.to/3DGqEH9
    🎙️ Mic Holder: amzn.to/3NAnM2U
    🎧 Headphones: amzn.to/3Wy7CuZ
    ⌨ Keyboard: amzn.to/3E2mSci
    📷 Webcam: amzn.to/3Tb0Ice
    VS Code Theme used: 🌃 Midnight Synth
    Suggest, ask doubts in the comments and share these videos to help!
    Thanks for Watching!
    #reactjs #mongodb #nextjs

ความคิดเห็น • 145

  • @udithkumarv734
    @udithkumarv734 ปีที่แล้ว +8

    I was looking through the internet for hours and couldn't find a way to display content from mongo using SSR, this video instantly helped me. ggs

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      I'm glad this was helpful to you 🙂

  • @nitexpress7163
    @nitexpress7163 ปีที่แล้ว +2

    I was just confused about next JS & MongoDB task. Now, I have understood everything. Very helpful video!

  • @Firewallnad
    @Firewallnad 7 หลายเดือนก่อน +1

    countless nights connecting my mongodb without errors, and tou are the hero
    😇

    • @MaxProgramming
      @MaxProgramming  7 หลายเดือนก่อน

      Thank you for the kind words 🙂

    • @nxtalex10
      @nxtalex10 7 หลายเดือนก่อน

      can you help? i have an app folder but not a pages folder?@@MaxProgramming

  • @Stellarspace95
    @Stellarspace95 7 หลายเดือนก่อน +1

    I am back again just to say you saved my week. 🎉 12 hours later and it’s working man. This tutorial is gold. Good STUFF

    • @MaxProgramming
      @MaxProgramming  7 หลายเดือนก่อน +1

      I am so happy it worked as expected!

    • @Stellarspace95
      @Stellarspace95 7 หลายเดือนก่อน +1

      @@MaxProgramming boss

  • @upliftmedia4722
    @upliftmedia4722 ปีที่แล้ว +2

    Nice explanation. I've been searching for hours for the specific instruction on how to go about my project, and your video nailed it. Simple and helpful. Thanks and more power to you.

  • @escalatedpumpkin
    @escalatedpumpkin ปีที่แล้ว +2

    Great video man. Was bashing my head agains the wall all day with this as it's been a while since I've used Mongo and mongoose and you've just saved us a lot of time. Appreciate it! I also would love to see a full project with NextJS, Mongo and Redux as another commenter said, if you ever get around to it. Cheers.

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Thanks Tyler!
      I gotta get my hands dirty with Redux and then I'll make a tutorial of the project with the same stack.
      By the way would you like to see that in the Next.js app directory?

    • @escalatedpumpkin
      @escalatedpumpkin ปีที่แล้ว +1

      @@MaxProgramming Whichever you see fit is fine with me. We’re currently using the pages directory but will eventually have to re-factor for the app directory, so sounds good to me.
      Cheers

  • @justingreen6561
    @justingreen6561 2 ปีที่แล้ว +1

    mann, i had some of that model/models error earlier playing around on this. glad i did and then got your explanation. appreciate the vid!

  • @robertosipovitch3794
    @robertosipovitch3794 2 ปีที่แล้ว +3

    Thank You for this, If you have more videos that are simple and clear like this one I will be watching them!

  • @realMenwa
    @realMenwa ปีที่แล้ว +2

    Really great presentation. The most impactful parts were explanations on common errors and how to solve them.

  • @Stellarspace95
    @Stellarspace95 7 หลายเดือนก่อน +1

    Dude if this works, you’re my actual Superman

  • @abusamuel806
    @abusamuel806 ปีที่แล้ว +1

    Wonderful explanation. With this I can figure out the Delete and Update to make a CRUD app. Exactly what I needed to move a PostgreSQL to MongoDB with NextJS.

  • @aniketjain6886
    @aniketjain6886 ปีที่แล้ว +1

    Outstanding !!! Brother 🍫❣️ just like a piece of cake. Keep it up .

  • @kushalmondal618
    @kushalmondal618 ปีที่แล้ว +1

    I was trying to integrate mongoDB with next app and I was looking for a solution where i can do the basic tasks , and with simplicity ofcourse, i also tried many articles and the example with mongo templates of next js as well , but could not help my self as they are manything but not simple, yours is a very good approach in that sense, Happy Hacking!

  • @EvandsonDantas
    @EvandsonDantas 2 ปีที่แล้ว +1

    Man, the best and simple video about mongoose and nextjs.

  • @gfjc1408
    @gfjc1408 2 ปีที่แล้ว +2

    Thank you so much man! I was getting so many errors all the time. You fixed them all :)

  • @khulanbayasgalan
    @khulanbayasgalan ปีที่แล้ว +1

    I don't usually comment on videos. But this is great one. Thank you so much.

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      😀 So nice of you! Glad it helped!

  • @ajanth
    @ajanth 2 ปีที่แล้ว +2

    Thank you so much for this video! Loved how you explained things clearly! Subscribed after this one :)

  • @TeluguFactsTV
    @TeluguFactsTV ปีที่แล้ว +1

    Simple and clear.

  • @sankalpmukim1052
    @sankalpmukim1052 2 ปีที่แล้ว +1

    Very nice practical look to building a edge case proof application quickly. Thanks

  • @markcalcagno676
    @markcalcagno676 ปีที่แล้ว +1

    This was incredibly helpful. Thank you

  • @faruksardar8829
    @faruksardar8829 ปีที่แล้ว +1

    Thank you so much Usman for this Tutorial, You deserve Nobel Prize man

  • @rodrigothiago0310
    @rodrigothiago0310 ปีที่แล้ว +2

    Thank you very much for this, It helped a lot. Keep doing the great work!

  • @umersaleem8483
    @umersaleem8483 ปีที่แล้ว +1

    Brother, this is really helpful tutorial for me. You gave a really good solution for using models directly on getServerSideProps(). Keep it up.

  • @bretrogers3747
    @bretrogers3747 ปีที่แล้ว +1

    Thank you for the clear explanation. Nicely done.

  • @jdev5096
    @jdev5096 ปีที่แล้ว +1

    Great video, hey just wanna ask, what font are you using in your vscode? I like the font, it's easy to read and the brackets also is highlited.

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว +1

      Thank you! I use the Cascadia Code font with ligatures.
      And yeah the bracket color is an in-built setting in VS Code

    • @jdev5096
      @jdev5096 ปีที่แล้ว +1

      @@MaxProgramming Thank you, applied it and loving it now.

  • @readul87
    @readul87 2 ปีที่แล้ว +2

    Wow your explanation is so easy and practical. Would please build a project with Redux, Next and Mongoose? Best of luck for your channel.

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว

      Thanks! Will surely try to do the project 🙂

  • @HasanKhan-nq2ch
    @HasanKhan-nq2ch ปีที่แล้ว +1

    u save my lot of time now i understand

  • @omprakashhardaha7736
    @omprakashhardaha7736 2 ปีที่แล้ว +1

    this and this are same was best part for me

  • @freefree8513
    @freefree8513 7 หลายเดือนก่อน +1

    Solved my problem, thanks!

  • @haduyamitrokia6159
    @haduyamitrokia6159 2 ปีที่แล้ว +1

    Thank you for the video it was simple and self explanatory

  • @guillermobreasoldano9233
    @guillermobreasoldano9233 ปีที่แล้ว +1

    Thanks for you help! You have a new subscriber

  • @alapottrachakma4706
    @alapottrachakma4706 2 ปีที่แล้ว +1

    subbed and followed on github. great explainations man loved every second of the video

  • @sandeepamarnath2272
    @sandeepamarnath2272 ปีที่แล้ว +1

    Very well explained. So helpful!

  • @maverick_wolfe
    @maverick_wolfe ปีที่แล้ว +1

    Absolutely amazing! Thank you so much! God bless you 🙏!

  • @sabassegovia3915
    @sabassegovia3915 2 ปีที่แล้ว +1

    Awesome walkthrough!

  • @jackied.v.carson6059
    @jackied.v.carson6059 ปีที่แล้ว +1

    Thank you for this outstanding tutorial!

  • @maskman4821
    @maskman4821 2 ปีที่แล้ว +1

    Thank you so much, this is very useful and helpful 👍

  • @lanzo19
    @lanzo19 ปีที่แล้ว +2

    Thanks brother

  • @sammybammy52
    @sammybammy52 2 ปีที่แล้ว +1

    This is a great video thanks bro👍🏾

  • @macxdeep
    @macxdeep ปีที่แล้ว +1

    Should i use this setup for blogs or cms would be better?

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Yep! This setup will work perfectly fine.

  • @AlineGrianti
    @AlineGrianti ปีที่แล้ว +1

    cool thank has been useful!

  • @KaraNoyan99
    @KaraNoyan99 2 ปีที่แล้ว +1

    thx for awesome video

  • @mohabbatshikderkowshik3739
    @mohabbatshikderkowshik3739 2 ปีที่แล้ว +1

    Thank you so much brother...

  • @kirkrepository
    @kirkrepository ปีที่แล้ว +1

    Would it matter if I fetched "tests" using getStaticProps instead or it's gotta be strictly getServerSideProps?

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว +1

      Doesn't matter if you use getStaticProps, getStaticPaths or getServerSideProps.
      These functions run on the server hence they are used to fetch the data. You possibly can't fetch data inside the React components

  • @UwU-dx5hu
    @UwU-dx5hu ปีที่แล้ว +1

    Thanks boss!!!

  • @rajenderkatkuri7642
    @rajenderkatkuri7642 2 ปีที่แล้ว +1

    Great video! On to the point.

  • @SoftwareEngineerMK
    @SoftwareEngineerMK ปีที่แล้ว +1

    Why did you put the mongodb connect function inside a route? It will run everytime someone hits the route

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Next.js doesn't behave like a fully functional backend API, hence, we can't connect to it at first and then use it later on.
      Whenever someone hits the API route, it has to connect to MongoDB first, and then it can make changes to the DB.
      If you wanna know more, I would suggest checking out this video that explains how Next.js's backend works compared to a different normal backend: th-cam.com/video/Rrz2q5uCHdE/w-d-xo.html

  • @sleechigo3759
    @sleechigo3759 ปีที่แล้ว +1

    thanks a lot for this, please on production, after deploying the site, once Irefresh the page it returns 500 error, server error, but on first load, it's normal only after refresh

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Wherever you deployed it, check of you put the environment variables right way.
      Also check the production logs. Because that's where you will get the actual error message

  • @namlenhat5003
    @namlenhat5003 ปีที่แล้ว +1

    What if I have many endpoints? Should I call connectMongo() in every one of them?

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว +1

      Yes. The way lambda functions/API routes are designed you will have to do that as far as I know

  • @FrozenLMAO
    @FrozenLMAO ปีที่แล้ว +1

    very good

  • @rayjenscode3501
    @rayjenscode3501 2 ปีที่แล้ว +1

    Thanks so much :)

  • @samuelahiadjipe3894
    @samuelahiadjipe3894 ปีที่แล้ว +1

    Great video! but sincierly, it was a bit confusing for me

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Thanks for the generous feedback 🙂. Let me know which part felt confusing to you and I'll work on it ✌️

  • @mustaneerhaider515
    @mustaneerhaider515 2 ปีที่แล้ว +1

    i think when you use connect it doesn't re creates the database conenction when hot module reload occurs in nextjs instead it reuses the old connection everytime maybe that's the reason you simple called connect function.

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว +1

      Actually the connect function connects to the database everytime. I don't think that the API routes preserve database connection as you can't also run websockets there

  • @user-zt1mx1fn6d
    @user-zt1mx1fn6d 9 หลายเดือนก่อน +1

    Thanks for video. but i am getting error. TypeError: mongoose__WEBPACK_IMPORTED_MODULE_0___default(...).connect is not a function

    • @MaxProgramming
      @MaxProgramming  9 หลายเดือนก่อน

      Try importing it the other way
      import * as mongoose from 'mongoose'
      And then use mongoose.connect()

  • @plamenyovchev
    @plamenyovchev 2 ปีที่แล้ว +1

    Is there a place in nextjs app where we can initialize the connection to mongodb as we would do in an express project ?

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว

      Actually, that might be possible in some way. But the way NextJS has the API Routes, it will eventually disconnect from MongoDB and that's why we connect to the DB everytime.

  • @johnappolo
    @johnappolo ปีที่แล้ว +1

    How can I make the data from getServerSideProps update every time I create new test using the button on UI. Do I use useState and useEffect? and if so, how can I do that please?

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว +1

      If you fetch data from getServerSideProps, the only way to get the updated data is by doing a full refresh.
      A better way to handle this is by using either SWR or React Query with the NextJS APi Routes.
      React Query: tanstack.com/query/v4
      Although you can also refetch data with React Query and getServerSideProps together:
      tanstack.com/query/v4/docs/guides/ssr

    • @johnappolo
      @johnappolo ปีที่แล้ว +1

      @@MaxProgramming Got it...thanks alot for the info and quick reply. And also for the great content you provide. You're helping a lot of ppl. 🙏

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว +1

      @@johnappolo Really appreciate your support 😄

  • @digiartpassion8513
    @digiartpassion8513 11 หลายเดือนก่อน

    Which VSCDOE plugin for theme you are using ? plz tell

    • @MaxProgramming
      @MaxProgramming  11 หลายเดือนก่อน

      I've used the Midnight Synth in this video

  • @niteshtak8484
    @niteshtak8484 2 ปีที่แล้ว +2

    Whenever i am trying to import any mongoDB connection file or other mango file into next.js component pages its throwing error "Unhandled Runtime Error
    TypeError: Cannot read properties of undefined (reading 'split')" . even in console i am getting the data using getServerSideProps but at UI this error is showing

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว

      The data you are getting is an array right? Try not using the split method in the UI and use JSON.stringify(array) and just render it like that.
      Also reply with the component code where the error occurs

    • @niteshtak8484
      @niteshtak8484 2 ปีที่แล้ว

      @@MaxProgramming I am not usi g any split method on the array coming from response, i double checked the code
      i am not sure its a package issue or something else

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว

      @@niteshtak8484 Okay so
      1. Try rendering the array with JSON.stringify(array)
      2. Show me the code where the error occurs. You might see the line number on the right of the error.
      Also is the error occurring in the browser or the terminal?

    • @niteshtak8484
      @niteshtak8484 2 ปีที่แล้ว

      @@MaxProgramming thats the issue the error and the line no is not showing in console nor in server side but the main things is that only doing import of mongo file in next app throwing error.. i cant share the code .. it seems weird for me also

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว

      @@niteshtak8484 Can you open chat.google.com and message me on maxprogramming05@gmail.com?

  • @tombrownanuma
    @tombrownanuma ปีที่แล้ว +1

    Great video, please how do you perform the DELETE operation. I tried this:
    async function Remove(req, res) {
    await connectDB()
    await FacebookModel.deleteOne({_id: req.params.id},
    function (err) {
    if (err) {
    console.log(err)
    }
    res.send("Deleted")
    })
    and pass the _id as /api/remove/${_id} but I got 404 error when click the deletebutton I made.

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Did you create a folder with square brackets to make this work?
      You have to create a folder like this
      my-app/
      ├─ pages/
      │ ├─ api/
      │ │ ├─ remove/
      │ │ │ ├─ [id].js

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      And once that part is done, you can get the particular id from the req URL using req.query.id
      Read more here on NextJS docs
      nextjs.org/docs/api-routes/dynamic-api-routes

    • @tombrownanuma
      @tombrownanuma ปีที่แล้ว +1

      Thanks, I got it fixed.

  • @obey_giant
    @obey_giant 2 ปีที่แล้ว +1

    What VS code theme are you using?

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว

      Midnight Synth.
      I specify the theme in the description of the video

  • @sarkaran
    @sarkaran ปีที่แล้ว +1

    no need to close connection ?

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Honestly, that is something I didn't take care of while making the video. But thanks for pointing out!

  • @EdgarLindo
    @EdgarLindo 2 ปีที่แล้ว +1

    Do you have the github for this code?

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว +2

      As of now, I don't. Let me know and I'll put that

    • @EdgarLindo
      @EdgarLindo 2 ปีที่แล้ว +1

      @@MaxProgramming Oh yes, if you have it, it would be very useful... thanks..

  • @faruksardar8829
    @faruksardar8829 ปีที่แล้ว +1

    Hi Usman, can you explain how I can get "authorization" from "req.header" in Next.js, For example:
    I want to destruct "authorization" from "req.headers" Something like this
    const { authorization } = req.headers
    But I am getting an error:
    TypeError: Cannot read properties of undefined (reading 'headers')
    > 7 | const { authorization } = req.headers
    | ^
    Thank you :)

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      This particular error means that "req" is undefined. Check the variable naming. Maybe that's different in your code. Or reply me the with the code

  • @PankajKumar-sh6wc
    @PankajKumar-sh6wc ปีที่แล้ว +1

    (0 , _mongoose.model) is not a function "This error is blown my mind" please help

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      1. Try restarting the server
      2. If that doesn't work, reply with your import code and the line where you used mongoose.model

    • @radekvlk8474
      @radekvlk8474 ปีที่แล้ว +1

      i had the same problem. i just pasted the function into the add.js file.
      export default async function handler(req, res) {
      console.log('connecting');
      await mongoose.connect(process.env.URI)
      console.log('connected');
      const test = await Test.create(req.body)
      res.json({test})
      }

  • @faruksardar8829
    @faruksardar8829 ปีที่แล้ว +1

    Does anyone have a solution for this
    OverwriteModelError: Cannot overwrite `Text` model once compiled.
    19 |
    > 20 | const Test = models.Test || mongoose.model('Text', dbSchema)
    | ^
    21 |
    22 | export default Test
    Thank you in Advance

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว +1

      Because in mongoose.model() you wrote *Text* and the other places you have *Test*. Change the Text inside mongoose.model to Test

  • @HS-pn3hy
    @HS-pn3hy ปีที่แล้ว +1

    been getting an error that points to my model
    __
    Unhandled Runtime Error
    TypeError: Cannot read properties of null (reading 'get')
    Source
    models\Flashcard.js (2:24) @ eval
    1 | import { Schema, model, models } from "mongoose"
    > 2 | const FlashcardSchema = new Schema({
    | ^
    __
    anyone ever see this error?

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Can you share your code in the reply? Your Flashcard.js file code?

    • @HS-pn3hy
      @HS-pn3hy ปีที่แล้ว

      @@MaxProgramming
      import mongoose from 'mongoose';
      const FlashcardSchema = new mongoose.Schema({
      question: {
      type: String,
      required: true,
      },
      user: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User"
      },
      answer:{
      type: String,
      required: true,
      },
      image:{
      type: String,
      },
      cloudinaryId:{
      type: String
      },
      topic:{
      type: String,
      }
      },{ timestamps: true })
      export default mongoose.models.Flashcard || mongoose.model('Flashcard', FlashcardSchema)

  • @Renato-fh2ez
    @Renato-fh2ez 2 ปีที่แล้ว +1

    Hey man, could You help me a little bit? I am just following the video and when I try to send post request I get this error
    CONNECTING TO MONGO
    MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
    Thanks
    edit: if someone has this error, go to MongoDB and add new IP whitelist- add 0.0.0.0/0

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว

      Glad you fixed it.
      But also finally when you use it for production, make sure to only whitelist *some IP addresses* . The one you whitelisted means everyone can access the database if they have the connection string 👍

    • @Renato-fh2ez
      @Renato-fh2ez 2 ปีที่แล้ว +1

      @@MaxProgramming Okey, will do! Thank you for amazing tutorial. It's pretty straight forward unlike other tutorials on youtube. Cheers!

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว

      @@Renato-fh2ez Are you connecting to mongodb and fetching with the model in the react component?
      You can only fetch data from MongoDB or any database in the API routes. And then call those API routes from your react components

  • @khageshbansal2400
    @khageshbansal2400 ปีที่แล้ว +1

    Where I can get this code. Do u have a GitHub repo

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Sorry I forgot. I'll push the code to GitHub and reply

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Here's the GitHub repo: github.com/max-programming/mongoose-with-nextjs

    • @khageshbansal2400
      @khageshbansal2400 ปีที่แล้ว +1

      @@MaxProgrammingpage not found☹️

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Try again. It's not private it's already public

  • @goosebosluk9573
    @goosebosluk9573 2 ปีที่แล้ว +1

    it can be implemented dynamic model acces with using model.DynamicNameVariable ?

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว +1

      If you want to make dynamic models, you can't just use model.DynamicNameVariable, if you have a variable that you want to use in this case you have to go with model[DynamicNameVariable]

    • @goosebosluk9573
      @goosebosluk9573 2 ปีที่แล้ว +1

      @@MaxProgramming Thanks for the answer i tried to
      const Metadata = mongoose.model[`${req.query.collectionAdd}metadata`]
      it gaveme error : The 2nd parameter to `mongoose.model()` should be a schema
      Could you give me further details

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว +1

      @@goosebosluk9573 actually my answer was about the models.Name. *model* is a function. I'll let you know about this soon

    • @MaxProgramming
      @MaxProgramming  2 ปีที่แล้ว +1

      @@goosebosluk9573
      model("NAME", Schema)
      do you want to have the NAME dynamic or do you want to pass in a dynamic schema?

    • @goosebosluk9573
      @goosebosluk9573 2 ปีที่แล้ว +1

      @@MaxProgramming Actually i want to dynamic NAME schema is static

  • @ibtesamRicky
    @ibtesamRicky ปีที่แล้ว +1

    Thank you so much!! You are a life saver!

  • @kashaanmahmood5311
    @kashaanmahmood5311 ปีที่แล้ว +1

    I was stuck with mongoose.model() and found your article. I hope you are safe and sound

  •  ปีที่แล้ว +1

    And How does it work with new app experimental?

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      You can still use pages/api folder to define custom API Routes and write server side code there.
      However there's no getStaticProps, getServerSideProps in the app directory anymore so you can just DIRECTLY fetch data in a page component (by making the page async).
      The only condition is you can't run client side code on that page. You have to create a different component with 'use client' on top

    •  ปีที่แล้ว +1

      @@MaxProgramming I would like to use new features, that promise to improve the workflow.

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      Yes and if you don't want to use the pages/api routes, Next 13 introduced Route Handlers instead of API Routes
      beta.nextjs.org/docs/routing/route-handlers

    •  ปีที่แล้ว +1

      @@MaxProgramming I can not understand how this all is used completely...starting from the mongo database until I get the data rendered on the page. Docs for me look like those written for advanced users of next.

    • @MaxProgramming
      @MaxProgramming  ปีที่แล้ว

      @ I guess you might be familiar with Mongoose/MongoDB but aren't with Next. I'd say right now don't use the Next app folder and stick with normal pages folder ☺️
      Also Next 13 app folder is not stable yet. It has HUGE problems too so it's better to use the pages folder to atleast get used to Next first.
      Let me know if you want a video on a specific topic on NextJS and I'll be more than happy to make a video