N
N
Neckvik2019-05-29 20:30:58
MongoDB
Neckvik, 2019-05-29 20:30:58

What is the correct way to efficiently connect to MongoDB in parallel?

const MongoClient = require("mongodb").MongoClient;   
const url = "mongodb://localhost:27017/";
const mongoClient = new MongoClient(url);
Here is an example, we have created a mono client, can we use the same client in parallel to connect to the database, or do we need to re-create it every time?
Well, or how to send many requests more efficiently without overloading node js.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2019-05-29
@Robur

Can. Moreover - you need a good reason to have more than 1 client in the application. the client keeps a pool of connections inside that is used for simultaneous requests, this pool can be customized to fit your needs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question