FallenRayne Dev One developer's random thoughts are better than nothing.


Playing around with MongoDB

So I have been messing around with MongoDB now for about 2 months on a side project that I am working on. I wanted to give a run down on my thoughts about Mongo and the PHP driver for it.


The installation of Mongo was relatively simple, mostly because I just installed it on my Ubuntu machine using the Debian package. Got it installed and running in under 20 minutes and had a interface downloaded and in place in about 10 minutes after that. The PHP driver was a simple as running

sudo pecl install mongo

and adding


to the php.ini file. All in all the process was extremely simple and there were no major hiccups.


The documentation is pretty clear overall. They have some good quick start tutorials and everything is pretty easy to follow. The documentation for the PHP driver is on php.net and just as you would expect PHP documentation, not perfect but most definitely not the worst out there. There have been enough sites that explain usage though I have had some troubles here and there, but I will explain those later.

Ease of Use:

This is where things get fun. Mongo is an extremely fun database to use. The logic of how the documents are constructed just makes so much sense to me as they are essentially just JSON strings. My major passion in web development is JavaScript so this just makes things fun. I am trying to do some great stuff with the queries because I am doing live filtering on the data as the user types. I currently have four different combo boxes and two text fields that the user can type into and automatically filter the content that is displayed. I am able to do this with Mongo's great query capabilities including its Regex search abilities.

The Regex search ability is probably my favorite so far. It has helped me figure out some of the more difficult problems and is extremely fast. I am live filtering on about 12,000 documents or so and checking for values that could be anywhere within a single property of the document and I am getting results back within a second. Regex has also allowed me to get around a missing feature of Mongo that is sorely missed and is probably my only issue with the database; there is no $and operator for the queries. You can do $or, $all, $in, $exists, $ne (not equals), and a bunch of other operators, but no $and. Here is a quick scenario to show why this is missed:

Here are three fake documents. Each one has an id and a tag. The tag just contains a few letters and the user is allowed to enter letters to try and find out if they are in the tag string. The user is expecting only the documents that have ALL of the letters in the tag string to come back, and the letter do not have to be in any particular order.


So the user enters in the values of B and C. Doc1 and Doc2 should be returned by not Doc3 because it is missing the letter C. Here is how I would want to create this query:

  $query1 = new MongoRegex('/B/i');
  $query2 = new MongoRegex('/C/i');
  $collection->find('$and'=>array('tag'=>$query1, 'tag'=>$query2));

I am using MongoRegex to create a Regex object that Mongo will understand. Both Regex objects are looking for a single character, and with the $and operator in the query, both regex queries have to return true to return the document. Now this is a very simple example but you can see why it would be useful to have to. Instead I had to resort to pure Regex. Here is the solution I ended up putting in place to handle this exact problem:

  $lettersAry = array();
  foreach($letters as $letter){
    $lettersAry[] = "(?=.*$letter)";
  $regex - '/^'.implode('',$lettersAry).'.*$/i';
  $collection->find('tag'=>new MongoRegex($regex));

That works perfectly for what I need and it puts all of the value checks into one regex object and makes it very easy to pass in as many letters as I want. Is this the perfect solution? Probably not. Does it do the trick? Most definitely.


Ok, so I didn't have too much to say I guess. I am still working on my app and I don't want to talk about it too much until it is closer to being finished. Hopefully I will be wrapping things up in the new few weeks and I will be able to share more. I will say that MongoDB is very fast, and is very easy to use. I have been able to just focus on my app and less on the database because of this. I haven't had to map out my entire database before I even touched a line of code, instead my database has morphed as I have worked on it. Need to add a new field? Oh well, throw it into the code and it is added! Yay! As a developer working on a side project I really don't want to have to think about the database more than I have too. I just want a place to dump my data and make it easy and fast to retrieve it. Thank you MongoDB for be my data dumping ground.

**Update** Ok, so I have re-written my code to use Kristina's suggestion and I got it working. Not sure why that didn't work for me the first few times I tried but I must have had something all screwy.

Tagged as: 3 Comments

Not a whole lot

Ok, so this has been a busy week for me at work so I haven't had as much time as I would have liked to work on some stuff. I am currently working on a private project that I hope to have out sometime in the next two months. Progress is slow due to working with code all day and not wanting to work on it much more until midnight, which then keeps me up till 1am and only an hour of work on my personal projects. :\

The new project is pretty cool though. I am using MongoDB, ExtJS, and possibly Symfony to throw it all together. MongoDB is the primary database, I might mixin MySQL at some point but right now MongoDB fits the bill perfectly. ExtJS is going to be the primary frontend with a Sencha Touch tie in for mobile devices and possibly a mobile app. Symfony is going to be mainly used for routing and authentication at this time.

I already have my database populated (which was a pain as I had to scrape a website to get all the data I needed as it is not readily available). I have the initial interface up and running and I am able to do basic queries right now using a ExtJS DataView as the main view with a ExtJS FormPanel controlling the complex filtering. I have to flesh out the filtering more and get that all routed through a solid filter class that I need to write and it should be mostly done.

Once at that point I just have to work on a couple of the other features of the app, clean up the code, and set my Ubuntu box up as my web server. I would use a host for this but it is difficult to find one that gives MongoDB access, and the ones that do normally charge extra. Not to mention that I am already using DreamHost (which ROCKS!) and they are doing pretty good with my other sites that I work on plus this blog. I could always set up a private server with them to use MongoDB but I am cheap at this point and I want to get the app into closed Beta and see how some of my friends like using it before I make any major decisions.

So like I said, hopefully in the next couple of months I will have the closed beta going and I can start making some of the bigger decisions as to where the project will lead. I will give updates on new features I implement and cool things I figure out, but until then I just need to get motivated and get this thing done.

Tagged as: No Comments

Android’s busiest little app – Tasker

So I explained my love for Tasker in my last post but I wanted to elaborate on the sheer awesomeness of this app. I have been using Tasker for about 10 days now and it is by far my most used app.

The coolest use I have found so far is that it can silence my phone when I have a scheduled calendar event in which I am classified as "busy". That is pretty great because I always forget to turn off my ringer during my meetings and it gets a little annoying. That is not the coolest part though. I have my phone set up so that if my wife sends me a text message that has the word "SOS" in it, it will automatically turn off silent mode, play the notification sound, wait 2 seconds, play it again, wait 2 seconds, and then turns silent mode back on. I don't always look down at my phone when in a meeting so if my wife REALLY needs to get a hold of me that is the perfect way to ensure I hear it.

I still need to try out a few more tasks. I seem to always have a desire to add more tasks into the app. I always want it to do a little bit more. I am not saying that it doesn't do enough, but there is just so much it can accomplish and I currently only have six tasks running. If anyone has any suggestions for some great tasks please share. Meanwhile I will start reading the forums more and seeing what other people have put together.


My new EVO!


originally uploaded by brandon.skeen.

Ok, so I finally got my new phone after a year of dealing with the growing disappointment (formally known as the Palm Pre). My wife got her EVO a couple of months ago and I have been jealous ever since. So last Saturday I finally was able to make the trek down to the store and purchase the phone of phones. This post is going to be a quick review of my phone and a couple of the apps that I am using.

First off, the picture that is attached is of my home screen. I am using ADW.Launcher Pro and so far have been loving it. I think this is where I will start my review. The customization possible on the Android operating system is nothing short of Linux like. That is good and bad. The good is that anything you want to accomplish is possible; the bad is that you will spend hours trying to accomplish just about anything which is a major time suck.

So far the hardware has been great. I have had no performance issues to really speak of. I have seen some lag with ADW.Launcher but I attribute that mostly to the fact that I am using a Live Wallpaper and the amount of crap I put on my phone. The camera has been pretty good so far, but not great. I have gotten a couple of nice photos but I need to get outside to try and take some better pictures but it is too damn cold out there. WiFi, Bluetooth, 3g has all been good. Setting up Bluetooth in my car to connect to Microsoft SYNC was crazy simple (way easier than the Pre).

The software is outstanding for the most part. There are some real gems out there but I have also found a ton of duds. The duds will happen (how many fart apps are in the iOS app store) so I am going to ignore those and focus on the greats.

Tasker - Absolutely amazing app that has a bit of a learning curve. This app took me 3 days of playing with before it finally all clicked on exactly how it works. If I would have sat down and read a tutorial I probably would have been better off, but what can I say, I am stubborn. Basically this app allows you to setup various tasks to run based on different events. If I move away from the cell tower near my house it automatically turns off my WiFi. If I plug my phone into ac power it will automatically bring up the desk clock. If I am scheduled to be in a meeting it will automatically silence the ringer. If it connects to SYNC it will automatically start up Pandora. These are just a few of the things this app can do. It is absolutely great!

Swype - A keyboard game changer! I have never been able to type as fast on a mobile device as I can with Swype. For those who don't know, Swype allows you to type by swiping your finger across the keyboard to the letters of the word. It is amazingly accurate! I decided to mess with it and tried to type something like "I am a lover of procrastination and evasion" and it picked up every word of it without issue. The best way to get a solid idea of what it can do is to watch the videos located on their site. Stunningly useful app.

ADW.Launcher Pro - Great home replacement app. Lots of great features and very nicely customizable.

Those are my favorite apps. There are a few others that are nice and do great things or have already been talked about to death (Angry Birds) so I will not talk about them again, but needless to say, the Android platform is starting to catch up to iOS, it will just take a little bit longer to get there.

So far, the only issue I really have had with the phone is streaming video to it. I really want to stream my movie library to my phone over WiFi and I just cannot get a consistent experience to save my life. I have tried Orb, TVersity, Twonky, and VLC, and nothing will consistently give me the video I want. This is my only major disappointment.

All in all, a great phone, amazing capabilities and all for a really good price right now (I got mine for only $99). I can't recommend the EVO enough. Even my non-techie wife loves hers.

Filed under: Personal No Comments