MongoDB
From Logic Wiki
Installation
- Go to http://www.mongodb.org/ and download relevant release
- unzip it
- md \data\db
- mongod
by typing mongod mongo deamon starts and it become ready to use on port displayed in the first line (27017)
CTRL + C exits the deamon
This is it !..
Changing Defaults
Specifiying a different data directory
md \somewhere\db
change the mongod.conf file and run this
mongod -f c:\somefolder\mongod.conf
in verbose field 1 is least 5 is most verbose
to run database as service
run cmd as administrator
mongod -f c:\somefolder\mongod.conf --install
net start mongodb
Connecting
mongo
Disconnecting
exit
or
CTRL + C
Some Commands
Which databases you have
show dbs
Which database are you in right now
db
Using a database
use foo
Requesting help
help
Creating a replica set on the same server
cd MyDb md\db1 md\db2 md\db3 @REM Primary start "a" mongod --dbpath ./db1 --port 30000 --replSet "demo" @REM Secondary start "a" mongod --dbpath ./db1 --port 40000 --replSet "demo" @REM Arbiter start "a" mongod --dbpath ./db3 --port 50000 --replSet "demo"
Connect
mongo --port 30000
Check
db.getMongo()
Create a configuration object
higher priority means higher cote to become primary
rs.initiate(demoConfig)
demo:STARTUP2> demo:PRIMARY>
MongoDB Shell
interactive shell is a java interpreter.