1. MongoDB Installation
2. Start and Stop the MongoDB Service
In Linux:
Start:/data/mongdb/bin/mongod -- fork -- auth -- dbpath =/data/mongdb/DB/-- Port 27017 -- logpath =/data/mongdb/logs/log.txt
Windows:
3. MongoDB shell commands
Help show helpshow DBS show database namesshow collections show collections in current databaseshow users show users in current databaseshow profile show most recent system. profile entries with time> = 1 msuse <dB Name> set curent database to <dB Name> dB. adduser (username, password) dB. removeuser (username) dB. clonedatabase (fromhost) dB. copydatabase (fromdb, todb, fromhost) dB. createcollection (name, {size :..., capped :..., MAX :...}) DB. getname () dB. dropdatabase () // Runs the collstats] command on each collection in the database DB. printcollectionstats () dB. currentop () displays the current operation in the dbdb. killop () kills the current operation in the dbdb. getprofilinglevel () dB. setprofilinglevel (level) 0 = off 1 = slow 2 = alldb. getreplicationinfo () dB. printreplicationinfo () dB. printslavereplicationinfo () dB. repairdatabase () dB. version () Current version of The serverdb. shutdownserver ()
DB. foo. drop () Drop the collectiondb. foo. dropindex (name) dB. foo. dropindexes () dB. foo. getindexes () dB. foo. ensureindex (keypattern, options)-options object has these possible fields: name, unique, dropdupsdb. foo. find ([query], [fields])-First parameter is an optional query filter. second parameter is optional set of fields Return . E.g. DB. foo. find ({X: 77}, {Name: 1, x: 1}) dB. foo. find (...). count () dB. foo. find (...). limit (n) dB. foo. find (...). skip (n) dB. foo. find (...). sort (...) DB. foo. findone ([query]) dB. foo. getdb () Get dB object associated with collectiondb. foo. count () dB. foo. group ({key :..., initial :..., reduce :... [, Cond:...]}) DB. foo. renamecollection (newname) renames the collectiondb. foo. stats () dB. foo. datasize () dB. foo. storagesize ()-includes free space allocated This Collectiondb. Foo. totalindexsize ()-size in bytes of all the indexesdb. Foo. totalsize ()-storage allocated For All data and indexesdb. foo. validate () (slow) dB. foo. insert (OBJ) dB. foo. update (query, object [, upsert_bool]) dB. foo. save (OBJ) dB. foo. remove (query)-remove objects matching query remove ({}) will remove all