A simplified wrapper layer above the node-mongodb-native driver that provides a streamlined API for MongoDB database operations
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Database administration capabilities including user management, indexing, and server statistics.
Access the admin interface through the database instance.
/**
* Get admin interface for database operations
* @returns {SkinAdmin} Admin instance
*/
db.admin();Core database administrative operations.
/**
* List all databases on the server
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
listDatabases(callback);
/**
* Get server status and statistics
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
serverStatus(callback);
/**
* Get server information
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
serverInfo(callback);
/**
* Ping the database server
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
ping(callback);Usage Examples:
const mongoskin = require('mongoskin');
const db = mongoskin.db('mongodb://localhost:27017/myapp');
const admin = db.admin();
// List all databases
admin.listDatabases((err, result) => {
if (err) throw err;
console.log('Databases:');
result.databases.forEach(db => {
console.log(`- ${db.name} (${db.sizeOnDisk} bytes)`);
});
});
// Get server status
admin.serverStatus((err, status) => {
if (err) throw err;
console.log('Server uptime:', status.uptime);
console.log('Current connections:', status.connections.current);
console.log('Memory usage:', status.mem);
});
// Get server information
admin.serverInfo((err, info) => {
if (err) throw err;
console.log('MongoDB version:', info.version);
console.log('Platform:', info.platform);
});
// Ping server
admin.ping((err, result) => {
if (err) throw err;
console.log('Server ping successful:', result);
});User and authentication management operations.
/**
* Add user to database
* @param {string} username - Username
* @param {string} password - Password
* @param {object} [options] - User options
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
addUser(username, password, options, callback);
/**
* Remove user from database
* @param {string} username - Username to remove
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
removeUser(username, callback);
/**
* Authenticate user credentials
* @param {string} username - Username
* @param {string} password - Password
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
authenticate(username, password, callback);
/**
* Logout current user
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
logout(callback);Usage Examples:
const admin = db.admin();
// Add new user
admin.addUser('newuser', 'password123', {
roles: ['readWrite']
}, (err, result) => {
if (err) throw err;
console.log('User added:', result);
});
// Authenticate user
admin.authenticate('username', 'password', (err, result) => {
if (err) throw err;
console.log('Authentication successful:', result);
});
// Remove user
admin.removeUser('olduser', (err, result) => {
if (err) throw err;
console.log('User removed:', result);
});
// Logout
admin.logout((err, result) => {
if (err) throw err;
console.log('Logged out:', result);
});Operations for managing MongoDB replica sets.
/**
* Get replica set status
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
replSetGetStatus(callback);
/**
* Initialize replica set
* @param {object} config - Replica set configuration
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
replSetInitiate(config, callback);
/**
* Reconfigure replica set
* @param {object} config - New replica set configuration
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
replSetReconfig(config, callback);Usage Examples:
const admin = db.admin();
// Get replica set status
admin.replSetGetStatus((err, status) => {
if (err) throw err;
console.log('Replica set status:', status.set);
console.log('Members:');
status.members.forEach(member => {
console.log(`- ${member.name}: ${member.stateStr}`);
});
});
// Initialize replica set
const config = {
_id: 'rs0',
members: [
{ _id: 0, host: 'localhost:27017' },
{ _id: 1, host: 'localhost:27018' },
{ _id: 2, host: 'localhost:27019' }
]
};
admin.replSetInitiate(config, (err, result) => {
if (err) throw err;
console.log('Replica set initialized:', result);
});MongoDB sharding cluster management.
/**
* Enable sharding for database
* @param {string} database - Database name
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
enableSharding(database, callback);
/**
* Shard collection
* @param {string} collection - Full collection name (db.collection)
* @param {object} key - Shard key
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
shardCollection(collection, key, callback);
/**
* Get sharding status
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
printShardingStatus(callback);Usage Examples:
const admin = db.admin();
// Enable sharding for database
admin.enableSharding('myapp', (err, result) => {
if (err) throw err;
console.log('Sharding enabled:', result);
});
// Shard a collection
admin.shardCollection('myapp.users', { _id: 1 }, (err, result) => {
if (err) throw err;
console.log('Collection sharded:', result);
});
// Get sharding status
admin.printShardingStatus((err, status) => {
if (err) throw err;
console.log('Sharding status:', status);
});Database profiling and performance monitoring.
/**
* Set profiling level
* @param {number} level - Profiling level (0=off, 1=slow ops, 2=all ops)
* @param {number} [slowms] - Slow operation threshold in milliseconds
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
setProfilingLevel(level, slowms, callback);
/**
* Get current profiling level
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
profilingLevel(callback);
/**
* Get profiling information
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
profilingInfo(callback);Usage Examples:
const admin = db.admin();
// Enable profiling for slow operations (>100ms)
admin.setProfilingLevel(1, 100, (err, result) => {
if (err) throw err;
console.log('Profiling enabled for slow ops:', result);
});
// Get current profiling level
admin.profilingLevel((err, level) => {
if (err) throw err;
console.log('Current profiling level:', level);
});
// Get profiling information
admin.profilingInfo((err, info) => {
if (err) throw err;
console.log('Profiling info:', info);
});
// Disable profiling
admin.setProfilingLevel(0, (err, result) => {
if (err) throw err;
console.log('Profiling disabled:', result);
});Global index management operations.
/**
* Reindex all collections in database
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
reIndex(callback);
/**
* Validate collection and indexes
* @param {string} collection - Collection name
* @param {function} callback - Callback function (err, result)
* @returns {void}
*/
validateCollection(collection, callback);Usage Examples:
const admin = db.admin();
// Reindex all collections
admin.reIndex((err, result) => {
if (err) throw err;
console.log('Reindex completed:', result);
});
// Validate collection
admin.validateCollection('users', (err, result) => {
if (err) throw err;
console.log('Collection validation:', result);
});Database and collection statistics.
/**
* Get database statistics
* @param {function} callback - Callback function (err, stats)
* @returns {void}
*/
stats(callback);
/**
* Get collection statistics
* @param {string} collection - Collection name
* @param {function} callback - Callback function (err, stats)
* @returns {void}
*/
collStats(collection, callback);Usage Examples:
const admin = db.admin();
// Get database statistics
admin.stats((err, stats) => {
if (err) throw err;
console.log('Database size:', stats.dataSize);
console.log('Index size:', stats.indexSize);
console.log('Collections:', stats.collections);
});
// Get collection statistics
admin.collStats('users', (err, stats) => {
if (err) throw err;
console.log('Collection documents:', stats.count);
console.log('Average document size:', stats.avgObjSize);
console.log('Total size:', stats.size);
});