Monthly Archives: March 2013

MongoDB getting started

Finally, I had a chance to install MongoDB. I made this page for my own reference. MongoDB offers free online course, so it will be a logical step to take this course after the installation and basic understanding. Installation seems very quick and easy. By looking at below basic command, I can see how powerful it can be when it is combined with other technologies.

  • Installation directory : C:\DevApps\mongodb\bin
  • Data : C:\DevApps\mongodb\data

Waiting for a connection

C:\DevApps\mongodb\bin>mongod.exe --dbpath c:\devapps\mongodb\data
Mon Mar 04 19:47:15 [initandlisten] MongoDB starting : pid=8100 port=27017 dbpath=
c:\devapps\mongodb\data 64-bit host=msjo-PC
Mon Mar 04 19:47:15 [initandlisten] db version v2.2.3, pdfile version 4.5
Mon Mar 04 19:47:15 [initandlisten] git version: f570771a5d8a3846eb7586xxxxxx4c2f4a96bf08
Mon Mar 04 19:47:15 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, 
build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
Mon Mar 04 19:47:15 [initandlisten] options: { dbpath: "c:\devapps\mongodb\data" }
Mon Mar 04 19:47:15 [initandlisten] journal dir=c:/devapps/mongodb/data/journal
Mon Mar 04 19:47:15 [initandlisten] recover : no journal files present, no recovery needed
Mon Mar 04 19:47:15 [initandlisten] waiting for connections on port 27017
Mon Mar 04 19:47:15 [websvr] admin web console waiting for connections on port 28017
//After execute mongo.exe
Mon Mar 04 20:17:35 [initandlisten] connection accepted from 127.0.0.1:2736 #1 (
1 connection now open)
Mon Mar 04 20:18:38 [FileAllocator] allocating new datafile c:/devapps/mongodb/data/test.ns, filling with zeroes...
Mon Mar 04 20:18:38 [FileAllocator] creating directory c:/devapps/mongodb/data/_tmp
Mon Mar 04 20:18:39 [FileAllocator] done allocating datafile c:/devapps/mongodb/
data/test.ns, size: 16MB,  took 0.058 secs
Mon Mar 04 20:18:39 [FileAllocator] allocating new datafile c:/devapps/mongodb/data/test.0, 
filling with zeroes...
Mon Mar 04 20:18:39 [FileAllocator] done allocating datafile c:/devapps/mongodb/data/test.0, 
size: 64MB,  took 0.156 secs
Mon Mar 04 20:18:39 [FileAllocator] allocating new datafile c:/devapps/mongodb/data/test.1, 
filling with zeroes...
Mon Mar 04 20:18:39 [conn1] build index test.test { _id: 1 }
Mon Mar 04 20:18:39 [conn1] build index done.  scanned 0 total records. 0.075 secs
Mon Mar 04 20:18:39 [conn1] insert test.test keyUpdates:0 locks(micros) w:301949 301ms
Mon Mar 04 20:18:39 [FileAllocator] done allocating datafile c:/devapps/mongodb/data/test.1, 
size: 128MB,  took 0.313 secs

New command prompt

C:\DevApps\mongodb\bin>mongo.exe
MongoDB shell version: 2.2.3
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
> db.test.save( {a:1})
> db.test.find()
{ "_id" : ObjectId("5135721e1652a3c0b2db4dcf"), "a" : 1 }
> show dbs
local   (empty)
test    0.203125GB
> use mydb
switched to db mydb
> db
mydb
> show dbs
local   (empty)
test    0.203125GB
> db
mydb
> j = { name: "mongo"}
{ "name" : "mongo" }
> k = {x:3}
{ "x" : 3 }
> db.things.insert(j)
> db.things.insert(k)
> show collections
system.indexes
things
> db.things.find()
{ "_id" : ObjectId("5135743d1652a3c0b2db4dd0"), "name" : "mongo" }
{ "_id" : ObjectId("513574441652a3c0b2db4dd1"), "x" : 3 }
>

It seems straight forward. Basically, it keeps the data key-value pair with internal unique ID. There are tons of example out there, so I will try to write a simple application to perform CRUD in my next posting.

Advertisements