Comments (9)
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.
from nodejs-quickstart.
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.
from nodejs-quickstart.
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.
from nodejs-quickstart.
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.
from nodejs-quickstart.
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?
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...
from nodejs-quickstart.
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.
from nodejs-quickstart.
What you'll want to do is create an instance of MongoClient when your app starts and then use that client throughout your app.
Although, how would you handle the case if the mongo connection dies in between the whole course of the application?
from nodejs-quickstart.
What you'll want to do is create an instance of MongoClient when your app starts and then use that client throughout your app.
Although, how would you handle the case if the mongo connection dies in between the whole course of the application?
But:
This is the correct answer. The accepted answer is very wrong as it says to open a connection pool for each request and then close it after doing so. Terrible architecture.
from nodejs-quickstart.
Although, how would you handle the case if the mongo connection dies in between the whole course of the application?
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.
from nodejs-quickstart.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodejs-quickstart.