MongoMinify Launched

Today I finally released the beta version of my MongoDB compression library for PHP. There still a lot of work to be done, but it's stable enough to use as a drop replacement for standard usage such as saving and retrieving data. Not only have I released the source code, but I've also submitted it as a composer package on packagist.org so everyone can include it in their projects very easily.

MongoDB MMS via Hamachi VPN

Today, I stumbled across a great way to use 10gen's MMS system with my Macbook Pro today without any kind of router reconfigure, firewall rule changing or even opening up mongod to the outside world. I simply took advantage of my personal Hamachi network with spans across all of my laptops, desktops and deployed servers. This is actually a paid Hamachi Pro account with 32 clients, but you can get a free one that allows up to 5 machines. Since I had the agent running on a server with Hamachi installed, I was simply able to go to the MMS control panel and add the internal network IP of my Macbook Pro. Even though it's an internal network, the MMS python agent makes requests from your agent machine, then connects with MMS separately, so the connection to my Macbook goes entirely through Hamachi and bypasses the outside world. This also has the advantage of being totally encrypted, and follows my machine wherever I go without having to update the IP inside MMS. The advantages of this are amazing, as it allows you to monitor and profile your local development environment without any extra tools and accompanied by mongostat it's a great way to find out what's actually happening on your machine. However, one downside of this is you have to re-enable the host in MMS if you've had your machine turned off for a while, as it becomes deactivated, but that's simple enough just to login and click the re-enable link. I'm always trying to find out useful new ways to make development easier, feel free to share any of your own!

MongoDB UK Workshops

Today, I attended the workshops leading up to the MongoDB UK event and learned so much from the amazing solutions experts over at 10gen. I can't wait to apply everything I learned such as replica sets, sharding and forward planned Schema Design. I say Schema Deisgn, but since Mongo is a Schema-less database I actually mean an implied data structure on how to highly optimize applications for different use cases. Before attending I had intermediate understanding of how mongo worked in a production environment, but now I feel confident I could multiple machines, back them up and shard them with ease. It was also quite fun being a physical shard as part of Chris‘s role play example which helped to visual how data is actually managed and passed around the machines. I'm even more excited for MongoDB UK tomorrow, which is of course, the main event. With speakers from AOL, Nokia, Cloud Foundry and gov.uk I'm sure there will be some amazing use cases to be learned from. I'll hopefully try and getting some posts written while I'm there tomorrow, and maybe even write up some coding examples from what I learn. Also looking forward to the Sharded pub crawl afterwards, but let's not tell the boss about that one!

Install MongoDB on Ubuntu 12.04

Here is a small script I whipped up while I was bored in the Travelodge waiting for #MongoDBUK. It's basically a drop in script to make sure MongoDB is installed with the default settings, and up to date. Very simple, but it saves running the commands manually each time. I may update this in the future when I find a better way to check if a key is already added before always inserting it #!/usr/bin/env sh # Sudo is required to install everything properly if [ "$(whoami)" != "root" ]; then echo "You need to use sudo to run this command" exit 0; fi echo "Installing MongoDB, please be patient, this could take a few minutes.." REPOSOURCE="deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" REPOFILE=/etc/apt/sources.list # Make sure packages are up to date and key exists apt-get update -qq && sudo apt-get upgrade -qq -y apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 # Append to repo if ! grep -Fxq "$REPOSOURCE" $REPOFILE then echo ": Adding $REPOSOURCE to $REPOFILE" echo "$REPOSOURCE" >> $REPOFILE apt-get update -qq fi # Run install apt-get install -y mongodb-10gen I normally put this in my home folder at ~/install-mongodb then run it using sudo ./install-mongodb. Note that sudo is actually a requirement, and the script will warn you if it you don't have root permissions. I will add more scripts in the next few hours as I go through the MongoDB UK workshops to have simple ways of switching configs for different scenarios and replacing the defaults to enable auth, for example. If you have any cool things you'd like me to write about regarding MongoDB please feel free to ask in the comments.

How to Rename a Field in MongoDB

Since MongoDB is technically a schema-less database, there aren't fields or columns that you are used to in things such as MySQL, and certainly no decent applications for managing data easily. Luckily, MongoDB has a lovely command shell which can be queried using simple JavaScript. The below command will rename a field, if you named it wrong in an initial stage of your app, like I've done a few times while learning. db.post.update({}, { $rename: {"old_name": "new_name"}}, false, true); The first parameter is your standard query, which I've left blank to match all documents by default. Please note that the 3rd and fourth paramters are actually required, or this won't work as by default only one document will be matched and an upsert will be applied, which isn't what you want in this situation. You can find the full documentation and explanation of the update function and the $rename command over at http://www.mongodb.org/display/DOCS/Updating#Updating-%24rename