Repair and restart mongo

  sudo chown -R mongodb:mongodb /var/lib/mongodb/
sudo -u mongodb mongod --dbpath=/var/lib/mongodb/ --repair
sudo service mongodb start

Finding indexes

> db.system.indexes.find()

Repair Mongo after bad termination

Remove mongod.lock

mongod --dbpath ~/data/db/ --repair

Mongo dump and restore

mongodump --db lux
tar -xvf dump-20120401.tar.gz
mongorestore dump

Drop database

use foo; db.dropDatabase();

Drop collection

drop the entire foo collection

GUIs for examining

Retrieve a subset of fields

OpenID, Django, Mongo - storage for openid transactions

/data/db ownership settings

Change ownership of /data/db and all files inside:

Storing files with MongoDB


Selecting by a field in EmbeddedDocument

receipt = Receipt.objects(__raw__={'': int(id)})
if receipt:
    receipt = receipt[0]
Last edited by Artem Dudarev, 2013-10-13 02:01:37. Edit