How should mongodb’s connection be understood

  mongodb, question

Mongodb also seems to have the concept of connection pool. The default maximum number of connections is 1024. Each connection will consume a certain amount of memory resources.

How do you understand this “connection” of mongobd? For example, in node, only one process starts the node program. When the application is started, the account password is configured and the database is specified. As the program is started, the Mongobd database is automatically connected. Is a connection to mongodb established at this time?

The node program after startup received many http requests. In each request operation, the previously created connection object will be called to perform the operation on mongodb. In other words, no matter how many http requests node receives, does it not always have only one connection to mongodb in the operation database? How exactly should you understand the number of mongodb connections? If this is the case, the default maximum of 1024 connections seems to be useless.

Mongodb also seems to have the concept of connection pool. The default maximum number of connections is 1024

There is a concept of connection pool, but 1024 does not know what it means. The maximum connection of the server is 65,000, and the default connection of the client Java/C# is 100. NodeJS should remember correctly that it should be 5 (because it is single thread). 1024 probably refers to ulimit? This is the maximum number of open files that the operating system defaults to. Everything in Linux is a file, so this limit is also limited to the number of network connections.

How do you understand this “connection” of mongobd? For example, in node, only one process starts the node program. When the application is started, the account password is configured and the database is specified. As the program is started, the Mongobd database is automatically connected. Is a connection to mongodb established at this time?

Yes

The node program after startup received many http requests. In each request operation, the previously created connection object will be called to perform the operation on mongodb. In other words, no matter how many http requests node receives, does it not always have only one connection to mongodb in the operation database? How exactly should you understand the number of mongodb connections? If this is the case, the default maximum of 1024 connections seems to be useless.

In fact, you mentioned the concept of connection pool yourself, whether you are using it or not.MongoClientOrMongoDatabaseObjects, all of which have connection pools in operation, will create more connections according to your degree of concurrency to meet the needs of all requests. Note that NodeJS is a single thread asynchronous non-blocking operation, so the number of requests does not necessarily equal the number of connections. But this is all about clients. As mentioned earlier, 1024 refers to ulimit, the server may face multiple clients, and the number of connections is the total number of client connections. And 1024 refers not only to the number of connections, it includes all handles that the server can open, so opening a data file, an index, and a connection takes up one of 1024. Therefore 1024 is usually not enough and should be adjusted.