Saturday, February 16, 2013

Hosted MongoDB connection problems

Just a quick story/solution today so that I don't completely neglect this blog. I recently changed a little project from using Azure to using AppFog, and everything was going fine until I started having some random connection issues with MongoDB. After deployment everything would work fine for a while, but then a few minutes later I wouldn't be able to connect the the database and I just got a random error or timeout.

After scratching my head for a while, Googling around for a solution, and changing my DB layer implementation a few times, I was out of ideas. Then I started to look into my configuration. I have my DB hosted at mongolab and I hadn't updated the hosting location - it was still hosted on Azure, but my AppFog site was hosted on AWS. I didn't think this would be a problem, but I cloned my DB and hosted it on AWS, and then everything started working perfectly.

So if anyone happens to have this problem, and you somehow manage to end up at this site - just make sure that your DB is hosted at the same place as your app.

1 comment:

  1. I've had this issue with MongoHQ on Azure. The problem is that Azure will timeout idle TCP sockets very quickly. My solution was to just ping the database with a query for a non-existent ID every 30 seconds. It aint pretty but it did work.