How to connect mongodb to Nextjs without mongoose? #73545
Replies: 1 comment 7 replies
-
Not necessarily, because the MongoDB Client, already does socket pooling, so a client can server concurrent requests. What you need to preserve is the client, https://www.mongodb.com/docs/drivers/node/current/faq/#how-does-connection-pooling-work-in-the-node-driver-:
And the code you've shared already does preserve the client. To find data you can read through: https://www.mongodb.com/docs/drivers/node/current/usage-examples/findOne/#std-label-node-usage-findone where the client is the client created in the file you shared.
Again, same point as above. |
Beta Was this translation helpful? Give feedback.
-
Summary
I am using nextjs 15 app router with mongodb as database.i simply want to fetch data in server component.Here i'm following the official example.
https://github.com/vercel/next.js/tree/canary/examples/with-mongodb
They use this file: mongodb.ts
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions