Page MenuHomeSealhub

bin_node_modules_mongodb_lib_mongodb_admin.js.html
No OneTemporary

bin_node_modules_mongodb_lib_mongodb_admin.js.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bin/node_modules/mongodb/lib/mongodb/admin.js - Prometheus Framework</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">
<div id="doc">
<div id="hd" class="yui3-g header">
<div class="yui3-u-3-4">
<h1><img src="../assets/css/logo.png" title="Prometheus Framework"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 0.1</em>
</div>
</div>
<div id="bd" class="yui3-g">
<div class="yui3-u-1-4">
<div id="docs-sidebar" class="sidebar apidocs">
<div id="api-list">
<h2 class="off-left">APIs</h2>
<div id="api-tabview" class="tabview">
<ul class="tabs">
<li><a href="#api-classes">Classes</a></li>
<li><a href="#api-modules">Modules</a></li>
</ul>
<div id="api-tabview-filter">
<input type="search" id="api-filter" placeholder="Type to filter APIs">
</div>
<div id="api-tabview-panel">
<ul id="api-classes" class="apis classes">
<li><a href="../classes/Represents a
Replicaset Configuration.html">Represents a
Replicaset Configuration</a></li>
<li><a href="../classes/Represents a BatchWriteResult.html">Represents a BatchWriteResult</a></li>
<li><a href="../classes/Represents a Collection.html">Represents a Collection</a></li>
<li><a href="../classes/Represents a Cursor..html">Represents a Cursor.</a></li>
<li><a href="../classes/Represents a CursorStream..html">Represents a CursorStream.</a></li>
<li><a href="../classes/Represents a Db.html">Represents a Db</a></li>
<li><a href="../classes/Represents a GridFS File Stream..html">Represents a GridFS File Stream.</a></li>
<li><a href="../classes/.html"></a></li>
<li><a href="../classes/Represents a MongoClient.html">Represents a MongoClient</a></li>
<li><a href="../classes/Represents a Mongos connection with failover to backup proxies.html">Represents a Mongos connection with failover to backup proxies</a></li>
<li><a href="../classes/Represents a OrderedBulkOperation.html">Represents a OrderedBulkOperation</a></li>
<li><a href="../classes/Represents a Read Preference..html">Represents a Read Preference.</a></li>
<li><a href="../classes/Represents a Server connection..html">Represents a Server connection.</a></li>
<li><a href="../classes/Represents a UnorderedBulkOperation.html">Represents a UnorderedBulkOperation</a></li>
<li><a href="../classes/Represents the Admin methods of MongoDB..html">Represents the Admin methods of MongoDB.</a></li>
<li><a href="../classes/Represents the Grid..html">Represents the Grid.</a></li>
<li><a href="../classes/Represents the GridStore..html">Represents the GridStore.</a></li>
</ul>
<ul id="api-modules" class="apis modules">
<li><a href="../modules/association.html">association</a></li>
<li><a href="../modules/database-accessor.html">database-accessor</a></li>
<li><a href="../modules/field-type-manager.html">field-type-manager</a></li>
<li><a href="../modules/resource-type-manager.html">resource-type-manager</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="yui3-u-3-4">
<div id="api-options">
Show:
<label for="api-show-inherited">
<input type="checkbox" id="api-show-inherited" checked>
Inherited
</label>
<label for="api-show-protected">
<input type="checkbox" id="api-show-protected">
Protected
</label>
<label for="api-show-private">
<input type="checkbox" id="api-show-private">
Private
</label>
<label for="api-show-deprecated">
<input type="checkbox" id="api-show-deprecated">
Deprecated
</label>
</div>
<div class="apidocs">
<div id="docs-main">
<div class="content">
<h1 class="file-heading">File: bin/node_modules/mongodb/lib/mongodb/admin.js</h1>
<div class="file">
<pre class="code prettyprint linenums">
/*!
* Module dependencies.
*/
var Collection = require(&#x27;./collection&#x27;).Collection,
Cursor = require(&#x27;./cursor&#x27;).Cursor,
DbCommand = require(&#x27;./commands/db_command&#x27;).DbCommand,
utils = require(&#x27;./utils&#x27;);
/**
* Allows the user to access the admin functionality of MongoDB
*
* @class Represents the Admin methods of MongoDB.
* @param {Object} db Current db instance we wish to perform Admin operations on.
* @return {Function} Constructor for Admin type.
*/
function Admin(db) {
if(!(this instanceof Admin)) return new Admin(db);
/**
* Retrieve the server information for the current
* instance of the db client
*
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from buildInfo or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.buildInfo = function(callback) {
this.serverInfo(callback);
}
/**
* Retrieve the server information for the current
* instance of the db client
*
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from serverInfo or null if an error occured.
* @return {null} Returns no result
* @api private
*/
this.serverInfo = function(callback) {
db.executeDbAdminCommand({buildinfo:1}, function(err, doc) {
if(err != null) return callback(err, null);
return callback(null, doc.documents[0]);
});
}
/**
* Retrieve this db&#x27;s server status.
*
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from serverStatus or null if an error occured.
* @return {null}
* @api public
*/
this.serverStatus = function(callback) {
var self = this;
db.executeDbAdminCommand({serverStatus: 1}, function(err, doc) {
if(err == null &amp;&amp; doc.documents[0].ok === 1) {
callback(null, doc.documents[0]);
} else {
if(err) return callback(err, false);
return callback(utils.toError(doc.documents[0]), false);
}
});
};
/**
* Retrieve the current profiling Level for MongoDB
*
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from profilingLevel or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.profilingLevel = function(callback) {
var self = this;
db.executeDbAdminCommand({profile:-1}, function(err, doc) {
doc = doc.documents[0];
if(err == null &amp;&amp; doc.ok === 1) {
var was = doc.was;
if(was == 0) return callback(null, &quot;off&quot;);
if(was == 1) return callback(null, &quot;slow_only&quot;);
if(was == 2) return callback(null, &quot;all&quot;);
return callback(new Error(&quot;Error: illegal profiling level value &quot; + was), null);
} else {
err != null ? callback(err, null) : callback(new Error(&quot;Error with profile command&quot;), null);
}
});
};
/**
* Ping the MongoDB server and retrieve results
*
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from ping or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.ping = function(options, callback) {
// Unpack calls
var args = Array.prototype.slice.call(arguments, 0);
db.executeDbAdminCommand({ping: 1}, args.pop());
}
/**
* Authenticate against MongoDB
*
* @param {String} username The user name for the authentication.
* @param {String} password The password for the authentication.
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from authenticate or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.authenticate = function(username, password, callback) {
db.authenticate(username, password, {authdb: &#x27;admin&#x27;}, function(err, doc) {
return callback(err, doc);
})
}
/**
* Logout current authenticated user
*
* @param {Object} [options] Optional parameters to the command.
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from logout or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.logout = function(callback) {
db.logout({authdb: &#x27;admin&#x27;}, function(err, doc) {
return callback(err, doc);
})
}
/**
* Add a user to the MongoDB server, if the user exists it will
* overwrite the current password
*
* Options
* - **w**, {Number/String, &gt; -1 || &#x27;majority&#x27; || tag name} the write concern for the operation where &lt; 1 is no acknowlegement of write and w &gt;= 1, w = &#x27;majority&#x27; or tag acknowledges the write
* - **wtimeout**, {Number, 0} set the timeout for waiting for write concern to finish (combines with w option)
* - **fsync**, (Boolean, default:false) write waits for fsync before returning, from MongoDB 2.6 on, fsync cannot be combined with journal
* - **j**, (Boolean, default:false) write waits for journal sync before returning
*
* @param {String} username The user name for the authentication.
* @param {String} password The password for the authentication.
* @param {Object} [options] additional options during update.
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from addUser or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.addUser = function(username, password, options, callback) {
var args = Array.prototype.slice.call(arguments, 2);
callback = args.pop();
options = args.length ? args.shift() : {};
// Set the db name to admin
options.dbName = &#x27;admin&#x27;;
// Add user
db.addUser(username, password, options, function(err, doc) {
return callback(err, doc);
})
}
/**
* Remove a user from the MongoDB server
*
* Options
* - **w**, {Number/String, &gt; -1 || &#x27;majority&#x27; || tag name} the write concern for the operation where &lt; 1 is no acknowlegement of write and w &gt;= 1, w = &#x27;majority&#x27; or tag acknowledges the write
* - **wtimeout**, {Number, 0} set the timeout for waiting for write concern to finish (combines with w option)
* - **fsync**, (Boolean, default:false) write waits for fsync before returning, from MongoDB 2.6 on, fsync cannot be combined with journal
* - **j**, (Boolean, default:false) write waits for journal sync before returning
*
* @param {String} username The user name for the authentication.
* @param {Object} [options] additional options during update.
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from removeUser or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.removeUser = function(username, options, callback) {
var self = this;
var args = Array.prototype.slice.call(arguments, 1);
callback = args.pop();
options = args.length ? args.shift() : {};
options.dbName = &#x27;admin&#x27;;
db.removeUser(username, options, function(err, doc) {
return callback(err, doc);
})
}
/**
* Set the current profiling level of MongoDB
*
* @param {String} level The new profiling level (off, slow_only, all)
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from setProfilingLevel or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.setProfilingLevel = function(level, callback) {
var self = this;
var command = {};
var profile = 0;
if(level == &quot;off&quot;) {
profile = 0;
} else if(level == &quot;slow_only&quot;) {
profile = 1;
} else if(level == &quot;all&quot;) {
profile = 2;
} else {
return callback(new Error(&quot;Error: illegal profiling level value &quot; + level));
}
// Set up the profile number
command[&#x27;profile&#x27;] = profile;
db.executeDbAdminCommand(command, function(err, doc) {
doc = doc.documents[0];
if(err == null &amp;&amp; doc.ok === 1)
return callback(null, level);
return err != null ? callback(err, null) : callback(new Error(&quot;Error with profile command&quot;), null);
});
};
/**
* Retrive the current profiling information for MongoDB
*
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from profilingInfo or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.profilingInfo = function(callback) {
try {
new Cursor(db, new Collection(db, DbCommand.SYSTEM_PROFILE_COLLECTION), {}, {}, {dbName: &#x27;admin&#x27;}).toArray(function(err, items) {
return callback(err, items);
});
} catch (err) {
return callback(err, null);
}
};
/**
* Execute a db command against the Admin database
*
* @param {Object} command A command object &#x60;{ping:1}&#x60;.
* @param {Object} [options] Optional parameters to the command.
* @param {Function} callback this will be called after executing this method. The command always return the whole result of the command as the second parameter.
* @return {null} Returns no result
* @api public
*/
this.command = function(command, options, callback) {
var self = this;
var args = Array.prototype.slice.call(arguments, 1);
callback = args.pop();
options = args.length ? args.shift() : {};
// Execute a command
db.executeDbAdminCommand(command, options, function(err, doc) {
// Ensure change before event loop executes
return callback != null ? callback(err, doc) : null;
});
}
/**
* Validate an existing collection
*
* @param {String} collectionName The name of the collection to validate.
* @param {Object} [options] Optional parameters to the command.
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from validateCollection or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.validateCollection = function(collectionName, options, callback) {
var args = Array.prototype.slice.call(arguments, 1);
callback = args.pop();
options = args.length ? args.shift() : {};
var self = this;
var command = {validate: collectionName};
var keys = Object.keys(options);
// Decorate command with extra options
for(var i = 0; i &lt; keys.length; i++) {
if(options.hasOwnProperty(keys[i])) {
command[keys[i]] = options[keys[i]];
}
}
db.command(command, function(err, doc) {
if(err != null) return callback(err, null);
if(doc.ok === 0)
return callback(new Error(&quot;Error with validate command&quot;), null);
if(doc.result != null &amp;&amp; doc.result.constructor != String)
return callback(new Error(&quot;Error with validation data&quot;), null);
if(doc.result != null &amp;&amp; doc.result.match(/exception|corrupt/) != null)
return callback(new Error(&quot;Error: invalid collection &quot; + collectionName), null);
if(doc.valid != null &amp;&amp; !doc.valid)
return callback(new Error(&quot;Error: invalid collection &quot; + collectionName), null);
return callback(null, doc);
});
};
/**
* List the available databases
*
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from listDatabases or null if an error occured.
* @return {null} Returns no result
* @api public
*/
this.listDatabases = function(callback) {
// Execute the listAllDatabases command
db.executeDbAdminCommand({listDatabases:1}, {}, function(err, doc) {
if(err != null) return callback(err, null);
return callback(null, doc.documents[0]);
});
}
/**
* Get ReplicaSet status
*
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the results from replSetGetStatus or null if an error occured.
* @return {null}
* @api public
*/
this.replSetGetStatus = function(callback) {
var self = this;
db.executeDbAdminCommand({replSetGetStatus:1}, function(err, doc) {
if(err == null &amp;&amp; doc.documents[0].ok === 1)
return callback(null, doc.documents[0]);
if(err) return callback(err, false);
return callback(utils.toError(doc.documents[0]), false);
});
};
};
/**
* @ignore
*/
exports.Admin = Admin;
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>

File Metadata

Mime Type
text/html
Expires
Sat, Sep 20, 14:46 (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
949295
Default Alt Text
bin_node_modules_mongodb_lib_mongodb_admin.js.html (28 KB)

Event Timeline