MongoDB

From Logic Wiki
Jump to: navigation, search

Installation

  1. Go to http://www.mongodb.org/ and download relevant release
  2. unzip it
  3. md \data\db
  4. 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

Mongo1.JPG higher priority means higher cote to become primary

rs.initiate(demoConfig)
demo:STARTUP2> 
demo:PRIMARY> 

MongoDB Shell

interactive shell is a java interpreter.