Sales Lead Tracking with PHP and MongoDB via MongoLab REST API

I'm not exactly a PHP programmer, although back in 2001 I did quite a bit of work with PHP and PostgreSQL for my job. I long ago stopped web programming in PHP and moved to Ruby, then Python and most recently Node.JS/JavaScript. I can't call myself a fan of the PHP language or paradigm either. However, PHP is everywhere and if you need some simple server-side code like a form mailer, it can be a good choice. Despite the disdain for PHP amongst most hackers, it remains extremely simple to deploy. Chances are you can just drop a .php file onto your web host and it will just work.


For my site offering hosting, support and consulting around Strider Continuous Integration & Deployment, I happened to be in just that situation. My web server is already configured for PHP and although I could spend the time to spin up a Python or Node.JS server, it adds needless complexity. All I wanted to do is one simple thing: track new sales leads in a MongoDB collection.

Lovely Free Cloud MongoDB from MongoLab

My web server doesn't run MongoDB, but it doesn't need to. MongoLab have a generous free plan which gives you a cloud-hosted MongoDB instance with up to 500M of storage. That is total overkill for my little sales lead database, and performance is more than adequate. Furthermore they will handle backup/restore and failover etc for me so it's likely a lot more reliable than running my own setup.

MongoDB REST API Benefits

Furthermore, MongoLab offer a HTTP REST API for MongoDB which is very fully-featured. Why would I want to use their REST API instead of a native driver? Well it turns out that my web server doesn't have the PHP MongoDB driver installed. It does however have the cURL library installed. Instead of bothering to figure out how to install the PHP MongoDB driver (which I suspect maybe be non-trivial under OpenBSD) I could just use their REST API.

Writing with MongoLab REST API from PHP

I didn't find much info online about using the REST API from PHP so I thought I'd post my little script here. It is quite straight forward. It simply JSON encodes some fields to produce the document I wish to write to my MongoDB collection. Then it sends a HTTP POST request with the JSON data as the POST body.

Niall O'Higgins is an author and software developer. He wrote the O'Reilly book MongoDB and Python. He also develops Strider Open Source Continuous Deployment and offers full-stack consulting services at

Read and Post Comments

3 Programmer Biases which Prevent you from Building a Successful Startup

Being a programmer is great. You understand the inner workings of the machine, you see inside the mysterious boxes which are ever more present in our lives. You have the knowledge to build new things, to wield data structures and algorithms to accomplish seemingly-magical feats of engineering.

However you also have biases and blind spots, which hold you back when it comes to building a successful product. Indeed, your very Computer Science training encourages and nurtures the thought processes which cause this bias.

1) Excessive simplification or "I could build Twitter in a weekend" syndrome

A very common problem among programmers is failing to see the true value of a new product or technology. Programming actively requires you to break larger problems down into simpler ones and pull out common patterns in order to solve tricky issues.

Simplification of the problem and pattern recognition work great when you are tasked with implementing a distributed database but may not be so useful when rigorously applied to nuanced product development.

When taken to an extreme, practically every single Internet product company could be simplified to "just an interface to a b-tree". For this reason, I am wary of the phrase "it's just X" when speaking with programmers about products.

When judging a product, an engineer should strive to answer the question "is there something new here", looking beyond just the nitty-gritty technical implementation details and trying hard to see what is enabled for the user that perhaps wasn't possible or as accessible before.

Examples: Twitter ("I could build it in a weekend"), Instagram ("it just tints photos and uploads them, Zuckerburg could have it coded for $10k"), iPad ("it's just a big iPod touch").

2) Inability to distinguish between cool technology and a marketable product

There are essentially three sets which ideas fall into:

  • Very large set: "Cool technologies" you could build
  • Smaller subset: "Cool technologies which would be useful to people but not make money"
  • Tiny subset: "Cool technologies which would be useful to people and also sustain a business".

As a programmer, the startup idea generation phase can be particularly dangerous because the temptation is to go off on some tangent of creating cool technology that nobody is actually willing to pay for or even use.

To be fair to the programmer mindset, it is extremely difficult to predict the success or failure of a given product in the market. Especially when there are huge distortions such as venture capital cash outs, acquisitions, IPOs etc. Startups have indeed simply created "cool technology" which made zero dollars and been sold for hundreds of millions.

But even if a VC or a big company like Google is in fact your target customer - there is still a very small set of ideas which are marketable to them, and to create the perceived value that they like to buy takes a lot more than something being merely a "cool technology".

Example of a cool technology: A new key-value store written in Haskell that is X% faster than FooDB
Example of a cool technology that is useful: Just about any modestly successful open source project
Example of a cool technology that is useful and can also sustain a business: Mixpanel

3) Failure to grasp the importance of relationships in business

Programmers have a reputation for not being the most socially adept people. The field is associated strongly with geeky introverts. There are exceptions and the situation is (fortunately) starting to become more diverse but nonetheless it is certainly true that a programmer's education does not typically emphasize the importance of human relationships.

The behavior of software is almost completely deterministic (barring hardware defects). Being a good programmer basically entails developing techniques and intuition for mentally traversing the deterministic program space. People and organizations, on the other hand, are far from deterministic. There are no hard rules about salary and stock compensation for example.

A large part of the value of companies is a function of the relationships of the people involved. For example, at least some portion of the 1 billion dollar price tag of Instagram surely owed to the fact that Kevin Systrom had an existing relationship with Mark Zuckerberg. There is a group of notable and highly successful entrepreneurs known as the PayPal Mafia.

Finding an awesome job with great compensation, getting help fixing a difficult bug, scoring publicity around a product launch - all these things get much easier with the right relationships. Go to meet ups, hang out at conferences, present cool stuff you are working on.

Most of all - don't be an asshole. Be tolerant of other people and open to new ideas. Always strive to treat people as you would like to be treated. Don't burn bridges unecessarily because you never know when you might be able to use their help in the future.

Niall O'Higgins is an author and software developer. He wrote the O'Reilly book MongoDB and Python. He also develops Strider Open Source Continuous Deployment and offers full-stack consulting services at

Read and Post Comments