-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One connection for each model? #15
Comments
It's just a quick start you can have one connection made and exported the client through which you can access the db on different code-blocks... |
It may be a quick start but I have seen many people follow the examples and make a connection for each data model, creating bad practice. I suggest that the examples live up to a real scenario without ceasing to be short examples, for example making a global declaration and sending the handler to the data layers, for example, through an additional variable in the constructor. |
Thanks for the feedback! I'll take this into consideration the next time I update the code and article series. What you'll want to do is create an instance of MongoClient when your app starts and then use that client throughout your app. |
Yes, I would appreciate it very much and avoid many bad practices of those who are just starting to use mongodb and use these examples as true bases. |
Although, how would you handle the case if the mongo connection dies in between the whole course of the application? |
But:
|
Without writing the code myself, I'm having trouble visualizing the flow. This is a good question to ask in the Community: community.mongodb.com. |
Look at this piece of code - this works well for me. I've been using it in a production application for some time. I use only one connection throughout the app. |
Thanks man, this seems to work great. |
Is it normal for each entity to have its own connection to the database? if I have 30 objects will I have 30 connections persistently?
The text was updated successfully, but these errors were encountered: