nuxt-mongoose
nuxt-mongoose copied to clipboard
Connect to MongoDB lazy
Hello, right now it seems like a connection to MongoDB is established when the Nuxt app starts. But when the app is deployed as a serverless function maybe a server handler is called that doesnt require any MongoDB connection. In this case the start of the app is delayed even tho MongoDB isnt even needed for the incoming request.
Is it possible to only connect to MongoDB when a query is executed?
For example:
- GET api/cats -> returns data from a third party service -> No MongoDB connection is established
- GET api/dogs -> calls model Dog.find() —> Now a MongoDB connection gets established
@MickL that's a pretty good idea! for sure it would be nice. thanks
I want to upvote this, it's something I just wanted to ask about 😀 Is there some way we could help with it? Do you have some idea how you would like to implement it?
@jankaderabek I tought if we could find the right hook for nitr it's possible but I couldn't find any to work, so I'm kinda stuck