Get the number of open connections in mongoDB usin

2019-02-25 17:09发布

My program requires a large number of connections to be open (Mongo). I get the error :

Too many connections open, can't open anymore

after 819 connections. I already know we can increase this limit. But that's not what I have in mind. I'm thinking of closing the MongoClient object, and then creating a new one again after 800 connections.

My thinking is that with a new mongoClient object all the connections will be closed and when I start/create it again, the connections will be opened again until 800. Thus not giving the error. (Let me know if this approach is totally wrong/ won't give the required results.)

For this I need to know the number of connections opened ATM. Is there any way to get this information using java?

1条回答
萌系小妹纸
2楼-- · 2019-02-25 17:37

You can get connection information by using the db.serverStatus() command. It has a connections subdocument which contains the total/available connections information.

For more information :

查看更多
登录 后发表回答