native_topology.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict';
  2. const Topology = require('../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: typeof options.emitError === 'boolean' ? options.emitError : true,
  15. maxPoolSize:
  16. typeof options.maxPoolSize === 'number'
  17. ? options.maxPoolSize
  18. : typeof options.poolSize === 'number'
  19. ? options.poolSize
  20. : 10,
  21. minPoolSize:
  22. typeof options.minPoolSize === 'number'
  23. ? options.minPoolSize
  24. : typeof options.minSize === 'number'
  25. ? options.minSize
  26. : 0,
  27. monitorCommands:
  28. typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
  29. }
  30. );
  31. // Translate any SSL options and other connectivity options
  32. clonedOptions = translateOptions(clonedOptions, options);
  33. // Socket options
  34. var socketOptions =
  35. options.socketOptions && Object.keys(options.socketOptions).length > 0
  36. ? options.socketOptions
  37. : options;
  38. // Translate all the options to the core types
  39. clonedOptions = translateOptions(clonedOptions, socketOptions);
  40. clonedOptions.serverApi = options.serverApi;
  41. clonedOptions.useUnifiedTopology = options.useUnifiedTopology;
  42. super(servers, clonedOptions);
  43. }
  44. capabilities() {
  45. if (this.s.sCapabilities) return this.s.sCapabilities;
  46. if (this.lastIsMaster() == null) return null;
  47. this.s.sCapabilities = new ServerCapabilities(this.lastIsMaster());
  48. return this.s.sCapabilities;
  49. }
  50. // Command
  51. command(ns, cmd, options, callback) {
  52. super.command(ns.toString(), cmd, options, callback);
  53. }
  54. // Insert
  55. insert(ns, ops, options, callback) {
  56. super.insert(ns.toString(), ops, options, callback);
  57. }
  58. // Update
  59. update(ns, ops, options, callback) {
  60. super.update(ns.toString(), ops, options, callback);
  61. }
  62. // Remove
  63. remove(ns, ops, options, callback) {
  64. super.remove(ns.toString(), ops, options, callback);
  65. }
  66. }
  67. module.exports = NativeTopology;