lib/mongodb/mongodb-core/lib/topologies/mongos.js
function(self, op, ns, ops, options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  // Pick a server
  let server = pickProxy(self);
  // No server found error out
  if (!server) return callback(new MongoError('no mongos proxy available'));

  if (!options.retryWrites || !options.session || !isRetryableWritesSupported(self)) {
    // Execute the command
    return server[op](ns, ops, options, callback);
  }

  // increment and assign txnNumber
  options.willRetryWrite = true;
  options.session.incrementTransactionNumber();

  server[op](ns, ops, options, (err, result) => {
    if (!err) return callback(null, result);
    if (!isRetryableError(err)) {
      return callback(err);
    }

    // Pick another server
    server = pickProxy(self);

    // No server found error out with original error
    if (!server || !isRetryableWritesSupported(server)) {
      return callback(err);
    }

    // rerun the operation
    server[op](ns, ops, options, callback);
  });
}
function(self, op, ns, ops, options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  // Pick a server
  let server = pickProxy(self);
  // No server found error out
  if (!server) return callback(new MongoError('no mongos proxy available'));

  if (!options.retryWrites || !options.session || !isRetryableWritesSupported(self)) {
    // Execute the command
    return server[op](ns, ops, options, callback);
  }

  // increment and assign txnNumber
  options.willRetryWrite = true;
  options.session.incrementTransactionNumber();

  server[op](ns, ops, options, (err, result) => {
    if (!err) return callback(null, result);
    if (!isRetryableError(err)) {
      return callback(err);
    }

    // Pick another server
    server = pickProxy(self);

    // No server found error out with original error
    if (!server || !isRetryableWritesSupported(server)) {
      return callback(err);
    }

    // rerun the operation
    server[op](ns, ops, options, callback);
  });
}
function ( self , op , ns , ops , options , callback ) { if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ; options = options || { } ; // Pick a server let server = pickProxy ( self ) ; // No server found error out if ( ! server ) return callback ( new MongoError ( 'no mongos proxy available' ) ) ; if ( ! options . retryWrites || ! options . session || ! isRetryableWritesSupported ( self ) ) { // Execute the command return server [ op ] ( ns , ops , options , callback ) ; } // increment and assign txnNumber options . willRetryWrite = true ; options . session . incrementTransactionNumber ( ) ; server [ op ] ( ns , ops , options , ( err , result ) => { if ( ! err ) return callback ( null , result ) ; if ( ! isRetryableError ( err ) ) { return callback ( err ) ; } // Pick another server server = pickProxy ( self ) ; // No server found error out with original error if ( ! server || ! isRetryableWritesSupported ( server ) ) { return callback ( err ) ; } // rerun the operation server [ op ] ( ns , ops , options , callback ) ; } ) ; }
Operations  Execute write operation
Operations Execute write operation