src/mongo/shell/replsettest.js
/**
     * Invokes the 'hello' command on each individual node and returns the current primary, or false
     * if none is found. Populates the following cached values:
     * '_primary': the current primary
     * '_secondaries': all nodes other than '_primary' (note this includes arbiters)
     * '_liveNodes': all currently reachable nodes
     */
Invokes the 'hello' command on each individual node and returns the current primary, or false
if none is found.
Invokes the ' hello ' command on each individual node and returns the current primary or false if none is found .
function _callHello() {
        self._liveNodes = [];
        self._primary = null;
        self._secondaries = [];
        var twoPrimaries = false;
        let canAcceptWrites = false;
        self.nodes.forEach(function(node) {
            try {
                node.setSecondaryOk();
                var n = node.getDB('admin')._helloOrLegacyHello();
                self._liveNodes.push(node);
                if (n.me && n.me == n.primary) {
                    if (self._primary) {
                        twoPrimaries = true;
                    } else {
                        self._primary = node;
                        canAcceptWrites = n.isWritablePrimary || n.ismaster;
                    }
                } else {
                    self._secondaries.push(node);
                }
            } catch (err) {
                print("ReplSetTest Could not call hello/ismaster on node " + node + ": " +
                      tojson(err));
                self._secondaries.push(node);
            }
        });
        if (twoPrimaries || !self._primary || !canAcceptWrites) {
            return false;
        }
        return self._primary;
    }
function _callHello ( ) { self . _liveNodes = [ ] ; self . _primary = null ; self . _secondaries = [ ] ; var twoPrimaries = false ; let canAcceptWrites = false ; self . nodes . forEach ( function ( node ) { try { node . setSecondaryOk ( ) ; var n = node . getDB ( 'admin' ) . _helloOrLegacyHello ( ) ; self . _liveNodes . push ( node ) ; if ( n . me && n . me == n . primary ) { if ( self . _primary ) { twoPrimaries = true ; } else { self . _primary = node ; canAcceptWrites = n . isWritablePrimary || n . ismaster ; } } else { self . _secondaries . push ( node ) ; } } catch ( err ) { print ( "ReplSetTest Could not call hello/ismaster on node " + node + ": " + tojson ( err ) ) ; self . _secondaries . push ( node ) ; } } ) ; if ( twoPrimaries || ! self . _primary || ! canAcceptWrites ) { return false ; } return self . _primary ; }
Invokes the 'hello' command on each individual node and returns the current primary, or false
 if none is found.
Invokes the ' hello ' command on each individual node and returns the current primary or false if none is found .
// Ensure that only one node is in primary state. // We verify that the node has a valid config by checking if n.me exists. Then, we // check to see if the node is in primary state.