native_topology.js
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const Topology = require('../core').Topology;
const ServerCapabilities = require('./topology_base').ServerCapabilities;
const Cursor = require('../cursor');
const translateOptions = require('../utils').translateOptions;
class NativeTopology extends Topology {
constructor(servers, options) {
options = options || {};
let clonedOptions = Object.assign(
{},
{
cursorFactory: Cursor,
reconnect: false,
emitError: typeof options.emitError === 'boolean' ? options.emitError : true,
size: typeof options.poolSize === 'number' ? options.poolSize : 5,
monitorCommands:
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
}
);
// Translate any SSL options and other connectivity options
clonedOptions = translateOptions(clonedOptions, options);
// Socket options
var socketOptions =
options.socketOptions && Object.keys(options.socketOptions).length > 0
? options.socketOptions
: options;
// Translate all the options to the core types
clonedOptions = translateOptions(clonedOptions, socketOptions);
super(servers, clonedOptions);
// Do we have an application specific string
if (options.appname) {
this.s.clientInfo.application = { name: options.appname };
}
}
capabilities() {
if (this.s.sCapabilities) return this.s.sCapabilities;
if (this.lastIsMaster() == null) return null;
this.s.sCapabilities = new ServerCapabilities(this.lastIsMaster());
return this.s.sCapabilities;
}
// Command
command(ns, cmd, options, callback) {
super.command(ns.toString(), cmd, options, callback);
}
// Insert
insert(ns, ops, options, callback) {
super.insert(ns.toString(), ops, options, callback);
}
// Update
update(ns, ops, options, callback) {
super.update(ns.toString(), ops, options, callback);
}
// Remove
remove(ns, ops, options, callback) {
super.remove(ns.toString(), ops, options, callback);
}
}
module.exports = NativeTopology;