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 Parse.com – and the performance is excellent

Authentication

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”}



		


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

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

librarykeycomments
cDataHandlerMj61W-201_t_zC9fJg1IzYiz3TLx7pV4jAbstracted interface to back end databases, and all known drivers
cCacheHandlerM3reA5eBxtwxSqCEgPywb9ai_d-phDA33Manages caching of query results
cNamedLockMpv7vUR0126U53sfSMXsAPai_d-phDA33Cross script locking of abstract resources
cFlattenMqxKdBrlw18FDd-X5zQLd7yz3TLx7pV4jFlattens 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

[do_widget id=jetpack_widget_social_icons-7] [do_widget id=text-5]