native_topology.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. const Topology = require('mongodb-core').Topology;
  3. const ServerCapabilities = require('./topology_base').ServerCapabilities;
  4. const Cursor = require('../cursor');
  5. const translateOptions = require('../utils').translateOptions;
  6. class NativeTopology extends Topology {
  7. constructor(servers, options) {
  8. options = options || {};
  9. let clonedOptions = Object.assign(
  10. {},
  11. {
  12. cursorFactory: Cursor,
  13. reconnect: false,
  14. emitError: options.emitError,
  15. size: options.poolSize,
  16. monitorCommands: options.monitorCommands
  17. }
  18. );
  19. // Translate any SSL options and other connectivity options
  20. clonedOptions = translateOptions(clonedOptions, options);
  21. // Socket options
  22. var socketOptions =
  23. options.socketOptions && Object.keys(options.socketOptions).length > 0
  24. ? options.socketOptions
  25. : options;
  26. // Translate all the options to the mongodb-core ones
  27. clonedOptions = translateOptions(clonedOptions, socketOptions);
  28. super(servers, clonedOptions);
  29. // Do we have an application specific string
  30. if (options.appname) {
  31. this.s.clientInfo.application = { name: options.appname };
  32. }
  33. }
  34. capabilities() {
  35. if (this.s.sCapabilities) return this.s.sCapabilities;
  36. if (this.lastIsMaster() == null) return null;
  37. this.s.sCapabilities = new ServerCapabilities(this.lastIsMaster());
  38. return this.s.sCapabilities;
  39. }
  40. }
  41. module.exports = NativeTopology;