Open mas-dude opened 7 years ago
Hi @mas-dude, you should ideally be holding open a connection for the duration of your application's life cycle since the underlying MongoDB driver manages connection reuse and pooling automatically.
With inversify, you would probably be best off injecting a connected Iridium instance singleton into your repositories. This also avoids the startup cost of building your models and improves V8's ability to optimise bytecode for your specific models.
Thanks @SPARTAN563. That is very helpful.
I had this exact same question. Might be worth addressing directly in the documentation.
I've forked the example repository in question that you were referring to as a sample, I've updated its dependencies and added socket.io injection. I will update it to implement this best practice, as i've done so with our closed source professional projects.
What is the best way to manage connections when using Iridium with Express? Should I be opening a single connection on app start and then use that for the life of the application or should I be creating a connection per request?
I have been following this sample which uses Iridium and creates a connection per repository operation but contradicts this advice.
Just wanting to make sure if there is anything in Iridium that might be doing something different.