Giter VIP home page Giter VIP logo

Comments (9)

yhojann-cl avatar yhojann-cl commented on May 25, 2024 3

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.

yhojann-cl avatar yhojann-cl commented on May 25, 2024 2

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.

yash-dxt avatar yash-dxt commented on May 25, 2024 1

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.

mizodo avatar mizodo commented on May 25, 2024 1

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.

singhpriansh avatar singhpriansh commented on May 25, 2024

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.

ljhaywar avatar ljhaywar commented on May 25, 2024

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.

yash-dxt avatar yash-dxt commented on May 25, 2024

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.

yhojann-cl avatar yhojann-cl commented on May 25, 2024

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?

Related: https://stackoverflow.com/questions/10656574/how-do-i-manage-mongodb-connections-in-a-node-js-web-application/14464750#14464750

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.

ljhaywar avatar ljhaywar commented on May 25, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.