How do I access available connections for Mongodb replicaset for mongoose v6

Hi! We used to be able to access available connections in mongodb replicaset via:

const primaryConnections = mongoose.connection.db.s.topology.s.coreTopology.s.replicaSetState.primary.s.pool.availableConnections.length

However, after upgrading to mongoose v6.2.10, this became undefined.

Tried mongoose.connection.db.s.client.topology.s.servers.s.pool (there are a number of internal metrics e.g. ConnectionPoolMetrics) which look like:

{
    txnConnections: 0,
    cursorConnections: 0,
    otherConnections: 0
}

However, they don’t seem to be reflecting the same values as what I’m seeing on my terminal when running mongod server locally. Not sure if this is the right metric to check?

Some additional information:

  • nodejs@18.12.0
  • mongoose@6.2.10
  • mongodb@4.2.2