How to rename a mongodb collection

On installing a sample node.js application the associated mongo files ended up with long collection names including ‘.’ and digit blocks.

To rename you cannot access the collection directly, as the dot-digit combination is illegal. Instead use

to solve the problem.

Export a mongo collection as csv

Started to create a script to do this, then realised mongoexport can do this out of the box!

Browse and delete records in mongodb

Script to restore all collections from mongodump

Feed this script the path to the dump directory created from mongodump to restore all collections. Handy to copy all mongo data to a new server.

Installing Mongodb on Debian Squeeze

Easy as

For the php driver we need php developer tools

Then add extension=mongo.so to the end of php.ini

 

Installing MongoDB on OS X

First grab the binary from this page:

http://www.mongodb.org/downloads

Extract to /opt/ and add the bin path to your .profile

Create /data/db dir

Give it the right ownership

chown /data/db

Now we can startup:

Now the PHP driver (XCode required)

Then add the following line to your php.ini file:

Done

Mongo db update gotcha

I was trying to remove an array field from a collection and it wasn’t working. Turned out the update command defaults to only updating the first found record rather than all (as sql would)

Standard update syntax to update all fields:

Backup a mongo database

Mongodb  Рawesome!

As few general admin tasks like backing up a full database:

and restoring from a backup:

Find by id in MongoDB

My copy of Mongo hub requires the syntax to be exactly right, and the error messages when I get it wrong are far from helpful. To do it right: