Mongo DB 101: Down the NoSql rabbit hole.

At some point I figure it would be good to move my ghost install off of the SQLite db it comes with and move over to something like mongo. With its' growing popularity and use accross multiple platforms I figured at some point it would be good to learn mongo.

How to install?

Well i'll admit, at first pass I decided this was a little tricker than I wanted and decided to be a punk and give up. Since then I grew a little more determinationa and became less intimidation with mucking around in the bash shell. To this end, I trudged on and this is the system I came up with:

1) Download the mongo files from this page here.

if you have wget installed you can wget that bad boy and put it on the desktop like so:

wget http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.4.8.tgz

#To extract type: 
tar -xzf http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.4.8.tgz  

2) Move the folder with all the binaries somewhere on your hard drive that you want it to permanately stay and rename it something catchy. I chose /usr/bin for mine. I figured i'd put it with the rest of my stuff.

mv ~/Desktop/mongodb-osx-x86_64-2.4.8 /usr/bin/m  

3) Cd into /usr/bin and symlink the binaries from the folder up into the root bin dir above. ( assuming youre following it my way. ) Peep the code below for an example on this:

sudo ln -s /usr/bin/m/mongo mongo  
sudo ln -s /usr/bin/m/mongod mongod  

Now you can run mongo by launching the dbserver and the mongo client like so:

#The rest flag enables some of the clickable stuff in the web admin console. It's optional.
mongod --rest  
mongo  

The Command Cheat Sheet

  • show dbs : shows the databases present.
  • use <dbname> : switches to that db.
  • show collections : shows the collections in a db.
  • db.<collectionName>.insert( myVar ): inserts data into a colleciton.
  • db.collectionName.find( ) : finds all records in a collection. db.collectionName.find( { name: "Paul" } ) : finds all records in a collection where the name is Paul.
  • db.dropDatabase( ) : deletes a database.
  • *db.answers.update({}, { $set: {losses: 0}}, {multi: true}); : updates all documents in a collection.

So what are the caveats?

  • warning: soft rlimit is 256. Minimum should be at least 1000. If you get this error then you need to run the following command.
sudo ulimit -n 1000  
#you can also check the info on this stuff with the -a flag.

Don't ask me what this does. Something about the File size limits and number of processes allowed to run by the system.

Ill probably update this article more in the future. As always, if you have questions, errata finds, or just want to say hi then feel free to!