Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix to bson to correctly detect regexp in bson, moved server status h…

…elper to admin
  • Loading branch information...
commit b381b161008f35a0b84b18077ece9a12628445f9 1 parent 89dfe66
@christkv authored
View
23 lib/mongodb/admin.js
@@ -48,6 +48,29 @@ Admin.prototype.serverInfo = function(callback) {
}
/**
+ * Retrieve this db's server status.
+ *
+ * @param {Function} callback returns the server status.
+ * @return {null}
+ * @api public
+ */
+Admin.prototype.serverStatus = function(callback) {
+ var self = this;
+
+ this._executeQueryCommand(DbCommand.createServerStatusCommand(this), function(err, result) {
+ if (err == null && result.documents[0].ok == 1) {
+ callback(null, result.documents[0]);
+ } else {
+ if (err) {
+ callback(err, false);
+ } else {
+ callback(self.wrap(result.documents[0]), false);
+ }
+ }
+ });
+};
+
+/**
* Retrieve the current profiling Level for MongoDB
*
* @param {Function} callback Callback function of format `function(err, result) {}`.
View
12 lib/mongodb/bson/bson.js
@@ -217,8 +217,8 @@ BSON.calculateObjectSize = function calculateObjectSize(object, serializeFunctio
*/
function calculateElement(name, value, serializeFunctions, isBuffer) {
isBuffer = typeof Buffer !== 'undefined';
-
- switch(typeof value) {
+
+ switch(typeof value) {
case 'string':
return 1 + (!isBuffer ? numberOfBytes(name) : Buffer.byteLength(name, 'utf8')) + 1 + 4 + (!isBuffer ? numberOfBytes(value) : Buffer.byteLength(value, 'utf8')) + 1;
case 'number':
@@ -271,7 +271,7 @@ function calculateElement(name, value, serializeFunctions, isBuffer) {
}
return (name != null ? ((!isBuffer ? numberOfBytes(name) : Buffer.byteLength(name, 'utf8')) + 1) : 0) + 1 + BSON.calculateObjectSize(ordered_values, serializeFunctions, isBuffer);
- } else if(value instanceof RegExp || String.call(value) === '[object RegExp]') {
+ } else if(value instanceof RegExp || toString.call(value) === '[object RegExp]') {
return (name != null ? ((!isBuffer ? numberOfBytes(name) : Buffer.byteLength(name, 'utf8')) + 1) : 0) + 1 + (!isBuffer ? numberOfBytes(value.source) : Buffer.byteLength(value.source, 'utf8')) + 1
+ (value.global ? 1 : 0) + (value.ignoreCase ? 1 : 0) + (value.multiline ? 1 : 0) + 1
} else {
@@ -279,7 +279,7 @@ function calculateElement(name, value, serializeFunctions, isBuffer) {
}
case 'function':
// WTF for 0.4.X where typeof /someregexp/ === 'function'
- if(value instanceof RegExp || String.call(value) === '[object RegExp]') {
+ if(value instanceof RegExp || toString.call(value) === '[object RegExp]') {
return (name != null ? ((!isBuffer ? numberOfBytes(name) : Buffer.byteLength(name, 'utf8')) + 1) : 0) + 1 + (!isBuffer ? numberOfBytes(value.source) : Buffer.byteLength(value.source, 'utf8')) + 1
+ (value.global ? 1 : 0) + (value.ignoreCase ? 1 : 0) + (value.multiline ? 1 : 0) + 1
} else {
@@ -786,7 +786,7 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
buffer[endIndex++] = 0x00;
// Return the end index
return endIndex;
- } else if(value instanceof RegExp || String.call(value) === '[object RegExp]') {
+ } else if(value instanceof RegExp || toString.call(value) === '[object RegExp]') {
// Write the type
buffer[index++] = BSON.BSON_DATA_REGEXP;
// Number of written bytes
@@ -829,7 +829,7 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
}
case 'function':
// WTF for 0.4.X where typeof /someregexp/ === 'function'
- if(value instanceof RegExp || String.call(value) === '[object RegExp]') {
+ if(value instanceof RegExp || toString.call(value) === '[object RegExp]') {
// Write the type
buffer[index++] = BSON.BSON_DATA_REGEXP;
// Number of written bytes
View
23 lib/mongodb/db.js
@@ -1150,29 +1150,6 @@ Db.prototype.dropDatabase = function(callback) {
};
/**
- * Retrieve this db's server status.
- *
- * @param {Function} callback returns the server status.
- * @return {null}
- * @api public
- */
-Db.prototype.serverStatus = function(callback) {
- var self = this;
-
- this._executeQueryCommand(DbCommand.createServerStatusCommand(this), function(err, result) {
- if (err == null && result.documents[0].ok == 1) {
- callback(null, result.documents[0]);
- } else {
- if (err) {
- callback(err, false);
- } else {
- callback(self.wrap(result.documents[0]), false);
- }
- }
- });
-};
-
-/**
* Register a handler
* @ignore
* @api private
View
50 test/admin_test.js
@@ -678,6 +678,56 @@ exports.shouldCorrectlyListAllAvailableDatabases = function(test) {
}
/**
+ * Retrieve the current server Info
+ *
+ * @_class admin
+ * @_function serverInfo
+ * @ignore
+ */
+exports.shouldCorrectlyRetrieveServerInfo = function(test) {
+ var db = new Db('integration_tests', new Server("127.0.0.1", 27017,
+ {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {native_parser: native_parser});
+
+ // Establish connection to db
+ db.open(function(err, db) {
+
+ // Drop the current database if it exists to avoid problems
+ db.dropDatabase(function(err, done) {
+
+ // Grab a collection object
+ db.collection('test', function(err, collection) {
+
+ // Force the creation of the collection by inserting a document
+ // Collections are not created until the first document is inserted
+ collection.insert({'a':1}, {safe:true}, function(err, doc) {
+
+ // Use the admin database for the operation
+ db.admin(function(err, adminDb) {
+
+ // Add the new user to the admin database
+ adminDb.addUser('admin', 'admin', function(err, result) {
+
+ // Authenticate using the newly added user
+ adminDb.authenticate('admin', 'admin', function(err, result) {
+
+ // Retrive the server Info
+ adminDb.serverInfo(function(err, info) {
+ test.equal(null, err);
+ test.ok(info != null);
+
+ db.close();
+ test.done();
+ })
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+}
+
+/**
* Retrieve the server information for the current
* instance of the db client
*
Please sign in to comment.
Something went wrong with that request. Please try again.