From 6c9a46546c5af4d19e0f4f6eb6b311475a9f0b83 Mon Sep 17 00:00:00 2001 From: Matti Jauhiainen Date: Sun, 23 May 2021 14:42:32 +0800 Subject: [PATCH] fix: Use isMaster instead of hello to support older instances (#201) --- src/cluster.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cluster.ts b/src/cluster.ts index 9f8ce6a0..d7224f6f 100644 --- a/src/cluster.ts +++ b/src/cluster.ts @@ -100,10 +100,12 @@ export class Cluster { const results = await Promise.all(this.#protocols.map((protocol) => { return protocol.commandSingle( "admin", - { hello: 1 }, + { isMaster: 1 }, ); })); - const masterIndex = results.findIndex((result) => result.isWritablePrimary); + const masterIndex = results.findIndex((result) => + result.isWritablePrimary || result.ismaster + ); if (masterIndex === -1) throw new Error(`Could not find a master node`); this.#masterIndex = masterIndex; }