How to list MongoDB connections - client ip and port

24 January,2020 by Jack Vamvas

Question: How can I list client ip , port and connection ID of connections to MongoDB? I want to connect through the MongoDB command line and extract this information as I'm testing some HA failover scenarios. 

Answer: There's a few different ways to extract the MongoDB connection details - for example you can use netstat. But from the command line - this syntax will report the details required 

 

db.currentOp(true).inprog.forEach(function(d){if(d.client)print(d.client, d.connectionId)})

 

Example output - clientip:port clientid:

127.0.0.1:55552 4668364
10.120.xxx.xxx:60942 4668363
10.120.xxx.xxx:60924 4668357

Read More on MongoDB

How to read MongoDB system log file

MongoDB cheatsheet


Author: Jack Vamvas (http://www.dba-ninja.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to list MongoDB connections - client ip and port


dba-ninja.com