0

In my cluster on Atlas, have a many connections in secondary nodes. How to list this connections?

When execute this command, list the current connections in primary node.

db.currentOp(true).inprog.reduce(
  (accumulator, connection) => {
    ipaddress = connection.client ? connection.client.split(":")[0] : "unknown";
    accumulator[ipaddress] = (accumulator[ipaddress] || 0) + 1;
    accumulator["TOTAL_CONNECTION_COUNT"]++;
    return accumulator;
  },
  { TOTAL_CONNECTION_COUNT: 0 }
)


{
    "TOTAL_CONNECTION_COUNT" : 229,
}

But, I have 700 connection in replicaSet.Connections in Atlas Server

Thank's

0

As mongo shell, this will print client IP:port, along with connection ID:

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

Note : Passing in true to db.currentOp() is equivalent to passing in a document of { "$all": true }. The following operations are equivalent:

db.currentOp(true)
db.currentOp( { "$all": true } )

For further ref here, here and here

  • 1
    This solution, list only connections in primary node, – Afonso Rodrigues Sep 17 at 12:35
0
  1. Go to the command line tools

enter image description here

  1. Copy mongostat command under Set Up Diagnostics section

enter image description here

  1. Update password and add --discover option at the end

  2. Run it in any command-line tool

  3. You should be able to see the number of connections as below for all primary and secondaries enter image description here

0
  1. Connect to the secondary node directly from mongo shell

mongo secondary-node-address:port --ssl --authenticationDatabase admin --username uname --password xxx

  1. You should be directly connected to the secondary node, now run the db.currentOP(true), it will list down all secondary node's processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.