Playing with MongoDB

Just for my reference, this is how I setup mongodb on my ubuntu 12.04. bash> sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 bash$ echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list bash> sudo apt-get update bash> sudo apt-get install mongodb-org bash> ls -lh /var/lib/mongodb total 81M drwxr-xr-x 2 mongodb nogroup 4.0K Apr 10 02:36 _tmp drwxr-xr-x 2 mongodb nogroup 4.0K Apr 10 02:36 journal -rw------- 1 mongodb nogroup 64M Apr 10 02:36 local.0 -rw------- 1 mongodb nogroup 16M Apr 10 02:36 local.ns -rwxr-xr-x 1 mongodb nogroup 5 Apr 10 02:36 mongod.lock bash> ls -lh /var/log/mongodb total 4.0K -rw-r--r-- 1 mongodb nogroup 2.3K Apr 10 02:37 mongod.log bash> ps aux | grep mongod mongodb 3106 2.1 1.4 357416 37048 ? Ssl 02:36 0:04 /usr/bin/mongod --config /etc/mongod.conf # Start mongo shell > use mydb switched to db mydb > a = { name : "manku-timma" } { "name" : "manku-timma" } > b = { age : 45 } { "age" : 45 } > mydb.testData.insert(a) 2014-04-10T02:46:07.610+0000 ReferenceError: mydb is not defined > db.testData.insert(a) WriteResult({ "nInserted" : 1 }) > db.testData.insert(b) WriteResult({ "nInserted" : 1 }) > show collections system.indexes testData > db.testData.find() { "_id" : ObjectId("53460605f93ad23879b22181"), "name" : "manku-timma" } { "_id" : ObjectId("53460608f93ad23879b22182"), "age" : 45 } > for (var i = 1; i <= 25; i++) db.testData.insert({ x : i }) WriteResult({ "nInserted" : 1 }) > db.testData.find() { "_id" : ObjectId("53460605f93ad23879b22181"), "name" : "manku-timma" } { "_id" : ObjectId("53460608f93ad23879b22182"), "age" : 45 } { "_id" : ObjectId("5346073af93ad23879b22183"), "x" : 1 } { "_id" : ObjectId("5346073af93ad23879b22184"), "x" : 2 } { "_id" : ObjectId("5346073af93ad23879b22185"), "x" : 3 } { "_id" : ObjectId("5346073af93ad23879b22186"), "x" : 4 } { "_id" : ObjectId("5346073af93ad23879b22187"), "x" : 5 } { "_id" : ObjectId("5346073af93ad23879b22188"), "x" : 6 } { "_id" : ObjectId("5346073af93ad23879b22189"), "x" : 7 } { "_id" : ObjectId("5346073af93ad23879b2218a"), "x" : 8 } { "_id" : ObjectId("5346073af93ad23879b2218b"), "x" : 9 } { "_id" : ObjectId("5346073af93ad23879b2218c"), "x" : 10 } { "_id" : ObjectId("5346073af93ad23879b2218d"), "x" : 11 } { "_id" : ObjectId("5346073af93ad23879b2218e"), "x" : 12 } { "_id" : ObjectId("5346073af93ad23879b2218f"), "x" : 13 } { "_id" : ObjectId("5346073af93ad23879b22190"), "x" : 14 } { "_id" : ObjectId("5346073af93ad23879b22191"), "x" : 15 } { "_id" : ObjectId("5346073af93ad23879b22192"), "x" : 16 } { "_id" : ObjectId("5346073af93ad23879b22193"), "x" : 17 } { "_id" : ObjectId("5346073af93ad23879b22194"), "x" : 18 } Type "it" for more > it { "_id" : ObjectId("5346073af93ad23879b22195"), "x" : 19 } { "_id" : ObjectId("5346073af93ad23879b22196"), "x" : 20 } { "_id" : ObjectId("5346073af93ad23879b22197"), "x" : 21 } { "_id" : ObjectId("5346073af93ad23879b22198"), "x" : 22 } { "_id" : ObjectId("5346073af93ad23879b22199"), "x" : 23 } { "_id" : ObjectId("5346073af93ad23879b2219a"), "x" : 24 } { "_id" : ObjectId("5346073af93ad23879b2219b"), "x" : 25 } > it no cursor bash> mongostat connected to: 127.0.0.1 insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time *0 *0 *0 *0 0 1|0 0 160m 511m 37m 0 # For a simple document insertion, I see about 2800 # inserts per second. Also about 500KBps of data flow. # Delete is instantaneous for very large number of # rows. > db.runCommand( ... { delete: "testData", deletes: [{q:{}, limit:0}]} ... ) { "ok" : 1, "n" : 409843 }

April 10, 2014 · 3 min · Bharath