Once you’re logged in to a mongodb server, you can check its information by invoking the hello command. You can just run db.hello() or db.runCommand({ hello: 1 })
The result below shows the details about the server, one of which indicating it’s the primary node.
db.hello()
{
isWritablePrimary: true,
topologyVersion: {
processId: ObjectId('69ee092cc7c19099773b9870'),
counter: Long('0')
},
maxBsonObjectSize: 16777216,
maxMessageSizeBytes: 48000000,
maxWriteBatchSize: 100000,
localTime: ISODate('2026-04-26T13:19:28.582Z'),
logicalSessionTimeoutMinutes: 30,
connectionId: 5,
minWireVersion: 0,
maxWireVersion: 21,
readOnly: false,
ok: 1
}