Wednesday, July 20, 2011

Mongo Commands

Update a mongo table

db.sp.update({"_id" : "SPP_000004"}, {$set : {"status" : "approved"}});


if you need to replace all occurence you need to pass two other arguments fist one is upsert that means whether it insert if not found and last one is the one say that it should be replaced in every
occurrence or not.

db.sp.update({"_id" : "SPP_000004"}, {$set : {"status" : "approved"}}, false ,true);


Export a collection
./mongoexport --db kite --collection sp > ~/Desktop/sp.dump.json


Import a collection

./mongoimport --db kite --collection sp --file ~/Desktop/sp.dump.json

Indexing

db.app.getIndexes();
db.app.ensureIndex({"app-id": 1});
db.app.dropIndex({"app-id": 1});

Compare Mongo with other noSql

http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

GetTime taken to query

db.sp.find().explain()