hot reload generatestaticparams mongoose issue
Unanswered
Siamese Crocodile posted this in #help-forum
Siamese CrocodileOP
hello!
i'm using mongoose as my database client, and i've tried using the official implementation of connecting the client (with a few changes, as seen here: https://dpaste.org/k16Y5). it's working perfectly fine, but as soon as i go to my page that uses
please excuse the whack code, i am pretty new to nextjs and overall web development with js/ts. i appreciate all your help!
i'm using mongoose as my database client, and i've tried using the official implementation of connecting the client (with a few changes, as seen here: https://dpaste.org/k16Y5). it's working perfectly fine, but as soon as i go to my page that uses
generateStaticParams, it will reconnect every time. i'm using a custom adapter in my code (https://dpaste.org/0YZO2), and i call the connectToDatabase() function in almost all adapter functions. it will print not connected: false every time, except for the first time it runs, but also every time generateStaticParams (which i noticed from the trace), meaning it creates one new connection every time i access the page using it. here's the code for that page: https://dpaste.org/Yx2eRplease excuse the whack code, i am pretty new to nextjs and overall web development with js/ts. i appreciate all your help!
11 Replies
Siamese CrocodileOP
can anyone help?
it could be the same hot reload issue on Prisma connection pool. they fixed it using a singleton pattern. im not sure mongoose stuff though.
@tafutada777 it could be the same hot reload issue on Prisma connection pool. they fixed it using a singleton pattern. im not sure mongoose stuff though.
Siamese CrocodileOP
yeah as you probably saw I'm storing it in the global variable
though it's like every time connectToDatabase() is run through generateStaticParams() it has a whole new environment or whatever you would call it
I guess one possible fix would be to store the state in a file
did you check the prisma solution?
@tafutada777 did you check the prisma solution?
Siamese CrocodileOP
where can I find that?
@tafutada777 https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices
Siamese CrocodileOP
thanks, i'll check it out
@Siamese Crocodile though it's like every time connectToDatabase() is run through generateStaticParams() it has a whole new environment or whatever you would call it
Siamese CrocodileOP
it seems like this is the case, cause if i use a file to prevent the connecting the second time it just doesn't manage to query the database, which is exactly what happens when ur not connected
so i suppose i will have to live with it lol