Home

MongoDB List of Commands

S:slave-ok R:read-lock W:write-lock A:admin-only
CommandAttributesHelp
_isSelf S { _isSelf : 1 } INTERNAL ONLY
_migrateClone Ainternal - should not be called directly
_recvChunkAbort Ainternal - should not be called directly
_recvChunkCommit Ainternal - should not be called directly
_recvChunkStart W Ainternal - should not be called directly
_recvChunkStatus Ainternal - should not be called directly
_testDistLockWithSyncCluster Ashould not be calling this directly
_transferMods Ainternal - should not be called directly
applyOps W examples: { applyOps : [ ] , preCondition : [ { ns : ... , q : ... , res : ... } ] }
authenticate W S internal
availableQueryOptions S
buildInfo S Aget version #, etc.
{ buildinfo:1 }
captrunc W
checkShardingIndex R Internal command.
clean W S internal
clone W clone this database from an instance of the db on another host
{ clone : "host13" }
cloneCollection { cloneCollection: <namespace>, from: <host> [,query: <query_filter>] [,copyIndexes:<bool>] }
Copies a collection from one server to another. Do not use on a single server as the destination is placed at the same db.collection (namespace) as the source.
Warning: the local copy of 'ns' is emptied before the copying begins. Any existing data will be lost there.
cloneCollectionAsCapped W { cloneCollectionAsCapped:<fromName>, toCollection:<toName>, size:<sizeInBytes> }
closeAllDatabases W AClose all database files.
A new request will cause an immediate reopening; thus, this is mostly for testing purposes.
collStats R S { collStats:"blog.posts" , scale : 1 } scale divides sizes e.g. for KB use 1024
connPoolStats S stats about connection pool
connPoolSync S internal
convertToCapped W { convertToCapped:<fromCollectionName>, size:<sizeInBytes> }
copydb W Acopy a database from another host to this host
usage: {copydb: 1, fromhost: <hostname>, fromdb: <db>, todb: <db>[, username: <username>, nonce: <nonce>, key: <key>]}
copydbgetnonce W Aget a nonce for subsequent copy db request from secure server
usage: {copydbgetnonce: 1, fromhost: <hostname>}
count R count objects in collection
create W create a collection
cursorInfo S example: { cursorInfo : 1 }
dataSize R S determine data size for a set of data in a certain range
example: { dataSize:"blog.posts", keyPattern:{x:1}, min:{x:10}, max:{x:55} }
keyPattern, min, and max parameters are optional.
note: This command may take a while to run
dbHash R S
dbStats R S example: { dbStats:1 }
diagLogging W S ADOCS/Monitoring and Diagnostics
distinct R S { distinct : 'collection name' , key : 'a.b' , query : {} }
driverOIDTest S
drop W drop a collection
{drop : <collectionName>}
dropDatabase W drop (delete) this database
dropIndexes W drop indexes for a collection
emptycapped W
eval Evaluate javascript at the server.
DOCS/Server-side Code Execution
features S return build level feature settings
filemd5 R S example: { filemd5 : ObjectId(aaaaaaa) , root : "fs" }
findAndModify W { findAndModify: "collection", query: {processed:false}, update: {$set: {processed:true}}, new: true}
{ findAndModify: "collection", query: {processed:false}, remove: true, sort: {priority:-1}}
Either update or remove is required, all other fields have default values.
Output is in the "value" field
forcedead W S Ainternal
forceerror S for testing purposes only. forces a user assertion exception
fsync W S ADOCS/fsync Command
geoNear R S DOCS/Geospatial Indexing
geoSearch R S
geoWalk R S
getCmdLineOpts S Aget argv
getLastError S return error status of the last operation on this connection
options:
fsync - fsync before returning, or wait for journal commit if running with --dur
w - await replication to w servers (including self) before returning
wtimeout - timeout for w in milliseconds
getParameter S Aget administrative option(s)
example:
{ getParameter:1, notablescan:1 }
supported so far:
quiet
notablescan
logLevel
syncdelay
{ getParameter:'*' } to get everything
getPrevError S check for errors since last reseterror commandcal
getShardMap S Ainternal
getShardVersion A example: { getShardVersion : 'alleyinsider.foo' }
getnonce S internal
getoptime S internal
godinsert W internal. for testing only.
group R DOCS/Aggregation
handshake S internal
isMaster S Check if this server is primary for a replica pair/set; also if it is --master or --slave in simple master/slave setups.
{ isMaster : 1 }
isinitialsynccomplete S
journalLatencyTest S Atest how long to write and fsync to a test file in the journal/ directory
listCommands S get a list of all db commands
listDatabases R S Alist databases on this server
logRotate S A
logout S de-authenticate
mapReduce Run a map/reduce operation on the server.
Note this is used for aggregation, not querying, in MongoDB.
DOCS/MapReduce
mapreduce.shardedfinish
medianKey R S Internal command.
example: { medianKey:"blog.posts", keyPattern:{x:1}, min:{x:10}, max:{x:55} }
NOTE: This command may take a while to run
moveChunk Ashould not be calling this directly
negotiatemaster W S A
ping S a way to check that the server is alive. responds immediately even if server is in a db lock.
profile W S enable or disable performance profiling
{ profile : <n> }
0=off 1=log slow ops 2=log all
-1 to get current values
DOCS/Database Profiler
reIndex W S re-index a collection
renameCollection W A example: { renameCollection: foo.a, to: bar.b }
repairDatabase W S repair database. also compacts. note: slow.
replSetElect S Ainternal
replSetFreeze S A{ replSetFreeze : <seconds> }'freeze' state of member to the extent we can do that. What this really means is that
this node will not attempt to become primary until the time period specified expires.
You can call again with {replSetFreeze:0} to unfreeze sooner.
A process restart unfreezes the member also.

DOCS/Replica Set Commands
replSetFresh S Ainternal
replSetGetRBID S Ainternal
replSetGetStatus S AReport status of a replica set from the POV of this server
{ replSetGetStatus : 1 }
DOCS/Replica Set Commands
replSetHeartbeat S internal
replSetInitiate S AInitiate/christen a replica set.
DOCS/Replica Set Commands
replSetReconfig S AAdjust configuration of a replica set
{ replSetReconfig : config_object }
DOCS/Replica Set Commands
replSetStepDown S A{ replSetStepDown : <seconds> }
Step down as primary. Will not try to reelect self for the specified time period (1 minute if no numeric secs value specified).
(If another member with same priority takes over in the meantime, it will stay primary.)
DOCS/Replica Set Commands
replSetTest S AJust for regression tests.
replacePeer W S Areplace a node in a replica pair
resetError S reset error state (used with getpreverror)
resync W S Aresync (from scratch) an out of date replica slave.
DOCS/Master Slave
serverStatus S returns lots of administrative server statistics
setParameter S Aset administrative option(s)
example:
{ setParameter:1, notablescan:true }
supported so far:
notablescan
logLevel
quiet
setShardVersion A example: { setShardVersion : 'alleyinsider.foo' , version : 1 , configdb : '' }
shardingState W A
shutdown S Ashutdown the database. must be ran against admin db and either (1) ran from localhost or (2) authenticated.
sleep S Ainternal testing command. Makes db block (in a read lock) for 100 seconds
w:true write lock
splitChunk Ainternal command usage only
example:
{ splitChunk:"db.foo" , keyPattern: {a:1} , min : {a:100} , max: {a:200} { splitKeys : [ {a:150} , ... ]}
splitVector R Internal command.
examples:
{ splitVector : "blog.post" , keyPattern:{x:1} , min:{x:10} , max:{x:20}, maxChunkSize:200 }
maxChunkSize unit in MBs
May optionally specify 'maxSplitPoints' and 'maxChunkObjects' to avoid traversing the whole chunk

{ splitVector : "blog.post" , keyPattern:{x:1} , min:{x:10} , max:{x:20}, force: true }
'force' will produce one split point even if data is small; defaults to false
NOTE: This command may take a while to run
top R S Ausage by collection
unsetSharding S A example: { unsetSharding : 1 }
validate R S Validate contents of a namespace by scanning its data structures for correctness. Slow.
whatsmyuri S {whatsmyuri:1}
writeBacksQueued S AReturns whether there are operations in the writeback queue at the time the command was called. This is an internal comand
writebacklisten S Ainternal