MongoDB Admin Commands

Originally posted from older blog on October 8th 2012

DBA Operations from the Shell

This page lists common DBA-class operations that one might perform from the MongoDB shell.Note one may also create .js scripts to run in the shell for administrative purposes.

help                         show help

show dbs                     show database names

show collections             show collections in current database

show users                   show users in current database

show profile                 show most recent system.profile entries with time >= 1ms

use <db name>                set curent database to <db name>

db.addUser (username, password)



db.copyDatabase(fromdb, todb, fromhost)

db.createCollection(name, { size : …, capped : …, max : … } )



// runs the collstats] command on each collection in the database


db.currentOp() displays the current operation in the db

db.killOp() kills the current operation in the db


db.setProfilingLevel(level) 0=off 1=slow 2=all





db.version() current version of the server


Commands for manipulating and inspecting a collection: drop the collection,options) – options object has these possible

fields: name, unique, dropDups [query] , [fields])       – first parameter is an optional

query filter. second parameter

is optional

set of fields to return.


{ x : 77 } ,

{ name : 1 , x : 1 } )…).count()…).limit(n)…).skip(n)…).sort(…)[query]) get DB object associated with collection { key : …, initial: …, reduce : …[, cond: …] } ) newName ) renames the collection – includes free space allocated to this collection – size in bytes of all the indexes – storage allocated for all data and indexes (slow), object[, upsert_bool])                   – remove objects matching query

remove({}) will remove all

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s