Skip to content

Commit 537a5c4

Browse files
committed
Expose parserType as property on topology objects
1 parent b034c83 commit 537a5c4

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

lib/mongos.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var release = os.release();
8888
* @fires Mongos#error
8989
* @fires Mongos#timeout
9090
* @fires Mongos#parseError
91+
* @property {string} parserType the parser type used (c++ or js).
9192
* @return {Mongos} a Mongos instance.
9293
*/
9394
var Mongos = function(servers, options) {
@@ -207,6 +208,12 @@ Object.defineProperty(Mongos.prototype, 'isMasterDoc', {
207208
enumerable:true, get: function() { return this.s.mongos.lastIsMaster(); }
208209
});
209210

211+
Object.defineProperty(Mongos.prototype, 'parserType', {
212+
enumerable:true, get: function() {
213+
return this.s.mongos.parserType;
214+
}
215+
});
216+
210217
// BSON property
211218
Object.defineProperty(Mongos.prototype, 'bson', {
212219
enumerable: true, get: function() {

lib/replset.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ var release = os.release();
9191
* @fires ReplSet#error
9292
* @fires ReplSet#timeout
9393
* @fires ReplSet#parseError
94+
* @property {string} parserType the parser type used (c++ or js).
9495
* @return {ReplSet} a ReplSet instance.
9596
*/
9697
var ReplSet = function(servers, options) {
@@ -215,6 +216,12 @@ Object.defineProperty(ReplSet.prototype, 'isMasterDoc', {
215216
enumerable:true, get: function() { return this.s.replset.lastIsMaster(); }
216217
});
217218

219+
Object.defineProperty(ReplSet.prototype, 'parserType', {
220+
enumerable:true, get: function() {
221+
return this.s.replset.parserType;
222+
}
223+
});
224+
218225
// BSON property
219226
Object.defineProperty(ReplSet.prototype, 'bson', {
220227
enumerable: true, get: function() {

lib/server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ var release = os.release();
8585
* @fires Server#timeout
8686
* @fires Server#parseError
8787
* @fires Server#reconnect
88+
* @property {string} parserType the parser type used (c++ or js).
8889
* @return {Server} a Server instance.
8990
*/
9091
var Server = function(host, port, options) {
@@ -212,6 +213,12 @@ Object.defineProperty(Server.prototype, 'isMasterDoc', {
212213
}
213214
});
214215

216+
Object.defineProperty(Server.prototype, 'parserType', {
217+
enumerable:true, get: function() {
218+
return this.s.server.parserType;
219+
}
220+
});
221+
215222
// Last ismaster
216223
Object.defineProperty(Server.prototype, 'poolSize', {
217224
enumerable:true, get: function() { return this.s.server.connections().length; }

test/functional/connection_tests.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,27 @@ exports['Should correctly connect to server using just events'] = {
8484
}
8585
}
8686

87+
/**
88+
* @ignore
89+
*/
90+
exports['Should correctly identify parser type'] = {
91+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
92+
93+
// The actual test we wish to run
94+
test: function(configuration, test) {
95+
var db = configuration.newDbInstance({w:1}, {poolSize:1, auto_reconnect:true});
96+
db.on('open', function(err, db) {
97+
test.equal(null, err);
98+
test.equal('js', db.serverConfig.parserType);
99+
100+
db.close();
101+
test.done();
102+
});
103+
104+
db.open();
105+
}
106+
}
107+
87108
/**
88109
* @ignore
89110
*/
@@ -232,7 +253,7 @@ exports.testConnectAllOptions = {
232253
{ server: {auto_reconnect: true, poolSize: 4},
233254
db: {native_parser: (process.env['TEST_NATIVE'] != null)} },
234255
connectionTester(test, 'testConnectAllOptions', function(db) {
235-
test.equal(1, db.serverConfig.poolSize);
256+
test.equal(1, db.serverConfig.poolSize);
236257
test.equal(4, db.serverConfig.s.server.s.pool.size);
237258
test.equal(true, db.serverConfig.autoReconnect);
238259
db.close();

0 commit comments

Comments
 (0)