Before installation of mongoDB you have to download it from the server and know system requirement.
System hardware requirement
Your system should be 64 bit. The 32-bit version of MongoDB can hold only 2GB of data for testing and evaluation purposes.
Download mongoDB Software
You can download the latest/appropriate release of MongoDB from http://www.mongodb.org/downloads before installation make sure you are downloading the correct version of MongoDB which is relevant according to your system (windows OS version).
How to install downloaded file
Please copy monngoDB MSI file and past at specific location where you want to install. Now double click on file and follow the instruction appears on screens.
You can install mongoDB at any location because it is self-contained and does not have any other system dependency.
Suppose you install the mongoDB in c:\\ drive, after that you will see a folder “mongodb-win32-x86_64-[version]” Here [version] is the version of MongoDb downloaded. You can rename this file name.
Now open the command prompt and run the following command.
Server
[Your mongodb file location]\bin mongod
For example C: \MongoDB\bin mongod
|
After executing above command if you found an error “data\db” db path not found or you wish to change db location then you need to specify any alternate path for \data\db by setting the path dbpath in mongod.exe. For the same issue following commands
In command prompt navigate to the bin directory present into the mongodb installation folder. Suppose my installation folder is D:\set up\mongodb.
C:\Users\XYZ>d:
D:\>cd "set up"
D:\set up>cd mongodb\bin
D:\set up\mongodb\bin>mongod.exe --dbpath "d:\set up\mongodb\data"
|
Client
If everything going well it will show a message “Waiting for Connection”. Now open a new command prompt and run the following command.
D:\set up\mongodb\bin>mongo.exe
MongoDB shell version: 2.4.7
Use test
>db.test.save( { myFirstField: 1 } )
>db.test.find()
{ "_id" : ObjectId(579a1567ac1b3f3732483de0), " myFirstField " : 1 }
|
This will show that mongodb is installed and run successfully. Next time when you run mongodb you need to issue only commands.
D:\set up\mongodb\bin>mongod.exe --dbpath "d:\set up\mongodb\data"
D:\set up\mongodb\bin>mongo.exe
|
MongoDB Help
If you wish to get a list of commands, type db.help() in mongoBD client. It will give you all commands of mongoDB as shown following.
DB methods:
db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]
db.auth(username, password)
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., capped : ..., max : ... } )
db.createUser(userDocument)
db.currentOp() displays currently executing operations in the db
db.dropDatabase()
db.eval() - deprecated
db.fsyncLock() flush data to disk and lock server for backups
db.fsyncUnlock() unlocks server following a db.fsyncLock()
db.getCollection(cname) same as db['cname'] or db.cname
db.getCollectionInfos([filter]) - returns a list that contains the names and options of the db's collections
db.getCollectionNames()
db.getLastError() - just returns the err msg string
db.getLastErrorObj() - return full status object
db.getLogComponents()
db.getMongo() get the server connection object
db.getMongo().setSlaveOk() allow queries on a replication slave server
db.getName()
db.getPrevError()
db.getProfilingLevel() - deprecated
db.getProfilingStatus() - returns if profiling is on and slow threshold
db.getReplicationInfo()
db.getSiblingDB(name) get the db at the same server as this one
db.getWriteConcern() - returns the write concern used for any operations on this db, inherited from server object if set
db.hostInfo() get details about the server's host
db.isMaster() check replica primary status
db.killOp(opid) kills the current operation in the db
db.listCommands() lists all the db commands
db.loadServerScripts() loads all the scripts in db.system.js
db.logout()
db.printCollectionStats()
db.printReplicationInfo()
db.printShardingStatus()
db.printSlaveReplicationInfo()
db.dropUser(username)
db.repairDatabase()
db.resetError()
db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into { cmdObj : 1 }
db.serverStatus()
db.setLogLevel(level,<component>)
db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all
db.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the db
db.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the db
db.setVerboseShell(flag) display extra information in shell output
db.shutdownServer()
db.stats()
db.version() current version of the server
|