native_topology.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. super(servers, clonedOptions);
  41. }
  42. capabilities() {
  43. if (this.s.sCapabilities) return this.s.sCapabilities;
  44. if (this.lastIsMaster() == null) return null;
  45. this.s.sCapabilities = new ServerCapabilities(this.lastIsMaster());
  46. return this.s.sCapabilities;
  47. }
  48. // Command
  49. command(ns, cmd, options, callback) {
  50. super.command(ns.toString(), cmd, options, callback);
  51. }
  52. // Insert
  53. insert(ns, ops, options, callback) {
  54. super.insert(ns.toString(), ops, options, callback);
  55. }
  56. // Update
  57. update(ns, ops, options, callback) {
  58. super.update(ns.toString(), ops, options, callback);
  59. }
  60. // Remove
  61. remove(ns, ops, options, callback) {
  62. super.remove(ns.toString(), ops, options, callback);
  63. }
  64. }
  65. module.exports = NativeTopology;