Driver MongoLab

This is the the driver for DB.MONGOLAB described in Database abstraction with google apps script 

The library reference is MPAHw_-cHNDxsYAg263J7Fai_d-phDA33

Background to implementation.

MongoLab offers a number of plans for cloud based MongoDB. I discovered they have a .5gb Free Sandbox plan, so I thought I'd give it a go. They recommend using their supplied libraries, but of course there is not one for Google Apps Script, so I used their REST API access to implement enough capabilities to cover all the features of Database abstraction with google apps script. Of course, MongoDB has zillions of other features that I don't use, but in this mode it's a great substitute for ScriptDB and alternative to - and the performance is excellent


It's simple - just an API key you can get from your MongoLab dashboard

Getting started

  • Sign up with MongoLab
  • Create a hosting plan
  • Create a database
  • Store your API key in your script Properties.

Getting a handle

Like all other drivers it all starts with getting a handle.  In this case, the MongoDB collection is 'customers', and the database I created is called 'xliberation'. The property is the one you stored your API key against, and should like this

{"restAPIKey":"your api key"}

  var userStore = PropertiesService.getScriptProperties();

  var handler = new cDataHandler.DataHandler (
      JSON.parse(userStore.getProperty("mongoLabKeys")) );
  if(!handler.isHappy()) {
    throw ( 'unable to get mongolab handler');

The example above uses the cDataHandler. Nowadays it's better to use the cDbAbstraction interface. An example is shown in the slides below. 

do something in 5 with gas-8-copy between databases

Now you're good to go. The syntax is the same for all back ends. See Some test cases for various backends for examples of various syntaxes, and see Comparing all back ends performance for how MongoLab performs. It's superfast as a scriptDB replacement.

The code

Here's some libraries you'll need or are used internally






Abstracted interface to back end databases, and all known drivers



Manages caching of query results



Cross script locking of abstract resources



Flattens complex objects to 1 level dot syntax objects  so they can be stored/queries in a 2 dimensional space

See more like this in Database abstraction with google apps script

For help and more information join our forum,follow the blog or follow me on twitter .