Get the number of open connections in mongoDB using java

让人想犯罪 __ 提交于 2019-12-02 04:13:48

问题


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:


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 :

  • Documentation of server status
  • Details of connections block


来源:https://stackoverflow.com/questions/21258696/get-the-number-of-open-connections-in-mongodb-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!