MongoLab Can Now Be CloudControlled in Europe!

Greetings, adventurers!

MongoLab is now available through Berlin-based European PaaS provider, cloudControl as an add-on. We're very excited to expand our services to include cloud-hosted databases for EU-hosted applications. As a user of cloudControl, your apps are hosted in Amazon EC2 Dublin. MongoLab will host your databases there too. You can develop and deploy a MongoDB + PHP application in the EU more easily than ever. And good news: MongoLab complies with the EU-SafeHarbor frameworks.

In this blog, I'll walk you through getting started with cloudControl and MongoLab using CCTRL, the command line client for working with cloudControl applications. It integrates well with git, which makes pushing code and deploying your app a breezy task. In the process, you'll see how easy it is to use. You'll also get a taste of the MongoLab web UI for administering your database, which lets you work with your data in the lightweight JSON syntax that makes MongoDB so attractive. We'll go through three stages:

  • Create a cloudControl account
  • Prepare the application
  • Seed the database from the MongoLab web UI
If you're already familiar with cloudControl, or if this isn't your first PaaS rodeo, you may benefit from this documentation, also.

Create a cloudControl Account

The cloudControl onboarding process guides you through some very simple steps to get your app up and running, and even provides demo code to use in the process. Here, just use the web interface to just create your account, (i.e. without the creating the demo app.) I'll walk you through using CCTRL to set up your application in the next stage.
  1. Install the CCTRL command-line client using cloudControl's instructions here.
  2. Open a browser and head to www.cloudcontrol.com.

  3. Click Sign up now to reach the sign up page, as shown below.

  4. Enter your desired user name, your email, and select password. Then, agree to the TOS and click Register.
  5. Check your email and follow the activation link to log in. The cloudControl onboarding process begins with adding your SSH key.

    Paste the contents of your id_rsa.pub file into this form and click Add my SSH key.  Then, head back to your Terminal, shell or Cmd window to use the CCTRL client from here on out. If you need guidance on SSH Keys in general, check this out.

Prepare the Application

Now we'll use CCTRL to set up our application and add the MongoLab add-on. Then we'll draw on and deploy a MongoDB + PHP sample app I've prepared. Finally, we'll deploy that sample code to cloudControl and visit our new webpage.
  1. To confirm activation success of your account, enter the below.  You will be prompted for your email and password. Use the cloudControl account email and password you just established:
    > cctrluser key
    Keys
    yRqMTxP3qy

    (The hash displayed is an ID for administering the stored key, should you need to in the future.)

  2. Now let's create the app using the cctrlapp create command. The syntax is cctrlapp <app_name> create <type>, where <app_name> is the name of the new app, and <type> is the type of application (which in this case is PHP). In the rest of the examples below, replace 'mymongolabtest' with your own app name.
    > cctrlapp mymongolabtest create php
    Git configuration found! Using "Git" as repository type.
    >

    This command also creates the default deployment for your app, in the form <app_name>/default. Use the fully-qualified deployment name going forward.

  3. Add the MongoLab add-on. You want the 240MB free MongoLab plan for this demo, so:
    >cctrlapp mymongolabtest/default addon.add mongolab.free
    >

    Adding the MongoLab add-on immediately provisions a MongoLab database and sets the MONGOLAB_URI config variable in your cloudControl credential's file. I'll detail that shortly.

  4. Obtain the MongoLab/cloudControl PHP sample code here by typing:
    > git clone https://github.com/mongolab/mongolab_cloudcontrol_sample.git
    Cloning into 'mongolab_cloudcontrol_sample'...
    remote: Counting objects: 6, done.
    remote: Compressing objects: 100% (5/5), done.
    remote: Total 6 (delta 0), reused 6 (delta 0)
    Unpacking objects: 100% (6/6), done.

    (if you need to install git click here).

    Once the git clone is complete, navigate to the cloned repository.

    > cd mongolab_cloudcontrol_sample
    >
  5. Take a look at index.php. You'll note two features:

    Credential File Access Code
    - CloudControl makes add-on provider configurations available in their CRED_FILE environment variable. We access the MONGOLAB_URI in CRED_FILE to get the MongoDB connection string populated by MongoLab.

    $credfile = file_get_contents($_ENV['CRED_FILE'], false);
    $credentials = json_decode($credfile, true);
    $uri = $credentials["MONGOLAB"]["MONGOLAB_URI"];

    The MONGOLAB_URI is of the form mongodb://<user>:<password>@<host>:<port>/<dbname>.

    Database Connection and Query Code - We use the URI we obtained to connect to and query the "cloudcontrolled" collection in our MongoDB database, and display all of the documents we find. Note that because we want to be as deft as possible, we're parsing the db name from the end of the URI.

    $dbname = substr($uri, strrpos($uri, "/")+1)
    $m = new Mongo($uri);
    $db = $m->selectDB($dbname);
    $col = new MongoCollection($db, "cloudcontrolled");
    $cursor = $col->find();
    foreach ($cursor as $doc) {
        echo json_encode($doc);
        echo "</br>";
    }
  6. This small bit of code is all you need to get started. Let's push it! The command is: cctrlapp <app_name>/default push. So, without changing directories:
    > cctrlapp mymongolabtest/default push
    Counting objects: 6, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (5/5), done.
    Writing objects: 100% (6/6), 1.48 KiB, done.
    Total 6 (delta 0), reused 0 (delta 0)
    
    >> Receiving push
    >> Compiling PHP
    >> Building image
    >> Uploading image (4.0K)
    
    To ssh://mymongolabtest@cloudcontrolled.com/repository.git
    * [new branch] master -> master
    >
  7. When CCTRL is run from a git repository directory, it automatically picks up your code.
  8. Next, we deploy our app with the command: cctrlapp <app_name>/default deploy.
    > cctrlapp mymongolabtest/default deploy
    >
  9. Within a a moment, your deployment will complete and your app will be available on the internet at <app_name>.cloudcontrolled.com.

Seed the Database

This is a rather empty page though. Wasn't the code getting documents out of a collection? Ah! Since our MongoLab database is brand-new, we need to add some data! The MongoLab web UI is a great place to drop a few seed documents, and it's available through SSO (single-sign-on) on your cloudControl console.

  1. Head to console.cloudcontrolled.com and log in. You'll start with a menu:
  2. The cloudControl console is still in alpha, so mind the continual improvements and click Applications -> <app_name> to reach your application landing page. Then in the Deployments section, select your default deployment <app_name>/default. Take a moment to familiarize yourself with the page and then click Add-Ons.
  3. Click Login next to your mongolab.free add-on, bypassing any pop-up blocking you have set up, and you will be redirected to the MongoLab web UI!

    The MongoLab Web UI is a lightweight JSON document editor and database management tool. Remember from the sample code above that you're selecting from the "cloudcontrolled" collection.
  4. Since there isn't a "cloudcontrolled" collection, click Add next to the Collections heading to create one.
  5. Now, click on your new collection in the Collections list to view it.
  6. Click Add next to the Documents heading to create one. You can copy and paste some JSON into this editor, or enter it yourself. MongoLab uses strict JSON, so be sure to quote your key names.
  7. When you're finished with your doc, click Save and go back to return to the collection page. Add a few more if you are so inclined.
  8. Now, refresh your app page and you should see the new documents printed below "Hello World"

There you have it. Now you're free to drop some of your own code to build out your MongoDB application while using the MongoLab web UI to help add initial data to your database. cloudControl and MongoLab hope you enjoy our services! As always, if you have any questions about this blog, or if something doesn't work the way you'd expect, email us at support@mongolab.com. We'll be happy to assist.

Keep your wits about you, and remember, the world still  needs adventurers.

Sincerely,
Eric@MongoLab 

17 Responses to MongoLab Can Now Be CloudControlled in Europe!

  1. is motor club america scam 2017/04/01 at 9:10 am #

    302726 332685Nice read, I just passed this onto a friend who was doing some research on that. And he just bought me lunch as I found it for him smile Therefore let me rephrase that: Thank you for lunch! 323184

  2. Best Best Online News 2017/04/06 at 12:30 pm #

    767802 729647You ought to experience a contest personally with the finest blogs on-line. Im going to suggest this page! 976228

  3. Best News Website in World 2017/04/06 at 3:54 pm #

    213836 931409have to do initial? Most entrepreneurs are so overwhelmed with their online business plans that 773536

  4. Best Best Online News in the World 2017/04/06 at 5:26 pm #

    807051 373469An incredibly interesting examine, I may possibly not concur entirely, but you do make some very valid points. 409581

  5. Best Best Online News in the World 2017/04/07 at 9:14 am #

    437964 878447Youre the very best, Its posts like this that keep me coming back and checking this website regularly, thanks for the info! 603

  6. Best Best Online News in the World 2017/04/07 at 4:38 pm #

    872720 780778I respect your piece of function, appreciate it for all of the intriguing content material . 434150

  7. Best Best Online News in the World 2017/04/07 at 10:17 pm #

    946251 188415Do you wear boxers or biefs? I wana bui em. 755535

  8. Best Best Online News in the World 2017/04/08 at 12:56 am #

    279441 599656Im positive your publish and internet web site is extremely constructed 591511

  9. GVK BIO 2017/04/08 at 11:12 am #

    282409 190934I want reading by way of and I conceive this internet site got some genuinely utilitarian stuff on it! . 273402

  10. Best Best Online News in the World 2017/04/08 at 2:16 pm #

    449498 660418Glad to be one of numerous visitants on this awful web website : D. 540119

  11. Best Best Online News in the World 2017/04/08 at 5:18 pm #

    441655 486670Hiya! Great blog! I happen to be a every day visitor to your website (somewhat much more like addict ) of this web site. Just wanted to say I appreciate your blogs and am searching forward for much more to come! 537959

  12. UK Chat Rooms 2017/04/08 at 8:33 pm #

    280260 425948Sorry for the huge review, but Im actually loving the new Zune, and hope this, as properly as the superb reviews some other folks have written, will aid you decide if it is the correct choice for you. 769120

  13. GVK Biosciences 2017/04/09 at 4:17 am #

    475660 734565The the next time I just read a blog, I really hope that this doesnt disappoint me approximately brussels. Get real, Yes, it was my option to read, but I really thought youd have some thing intriguing to say. All I hear is usually a couple of whining about something that you could fix when you werent too busy searching for attention. 278032

  14. 800613 622066As I internet web site possessor I believe the content material matter here is rattling magnificent , appreciate it for your hard function. You ought to maintain it up forever! Finest of luck. 251791

  15. Switch Energy Supplier 2017/04/21 at 1:00 am #

    995770 431890I was trying to locate this. Actually refreshing take on the details. Thanks a whole lot. 667683

  16. VaporSOUL 2017/04/30 at 7:02 pm #

    133331 450415Music began playing anytime I opened this web site, so irritating! 768032

  17. 161283 150791If running proves to be a dilemma then it could be wise to uncover alternative exercises such as circuit training, weight training, swimming or cycling. 295356

Leave a Reply