Terence Bennett - October 8, 2013
              <div class="hs-migrated-cms-post"> 
               <p><img id="img-1378227826564" class="alignLeft" src="//staticassets.dreamfactory.com/images/team-ben.jpg?t=1527092313664&amp;width=86&amp;height=57&amp;name=team-ben.jpg" alt="BenBusse" width="86" height="57" border="0" srcset="//staticassets.dreamfactory.com/images/team-ben.jpg?t=1527092313664&amp;width=43&amp;height=29&amp;name=team-ben.jpg 43w, //staticassets.dreamfactory.com/images/team-ben.jpg?t=1527092313664&amp;width=86&amp;height=57&amp;name=team-ben.jpg 86w, //staticassets.dreamfactory.com/images/team-ben.jpg?t=1527092313664&amp;width=129&amp;height=86&amp;name=team-ben.jpg 129w, //staticassets.dreamfactory.com/images/team-ben.jpg?t=1527092313664&amp;width=172&amp;height=114&amp;name=team-ben.jpg 172w, //staticassets.dreamfactory.com/images/team-ben.jpg?t=1527092313664&amp;width=215&amp;height=143&amp;name=team-ben.jpg 215w, //staticassets.dreamfactory.com/images/team-ben.jpg?t=1527092313664&amp;width=258&amp;height=171&amp;name=team-ben.jpg 258w" sizes="(max-width: 86px) 100vw, 86px">We’re excited to announce that we’ve partnered with MongoHQ. Now you can connect directly to any MongoHQ database instance from the DreamFactory Services Platform (DSP). In a nutshell, this new feature makes accessing your MongoHQ data really easy.</p> 
               <ol> 
                <li>Securely store your MongoHQ credentials on a server. You never want to do this on the client for security reasons!</li> 
                <li>Make database calls to your MongoHQ database with a ready-to-go REST API. Now you don’t have to write your own API to access MongoHQ. DreamFactory creates the API for you. Just make an API call and get a JSON document back from the server.</li> 
                <li>Apply CRUD permissions at the collection level based on user role. This is a great feature if you need to apply different data permissions for different users in your application.</li> 
               </ol> 
               <p>In this blog post, we’ll show you how to connect to MongoHQ in 60 seconds, quickly browse the REST API to access your data stored in MongoHQ, and apply CRUD permissions for different user roles.</p> 
               <p>Before getting started, you’ll need to <a href="https://tour.mongohq.com/c/dreamfactory">sign up for a MongoHQ account</a> if you don’t already have one. The link above provides developers a $50 credit for opening a new account with MongoHQ. </p> 
               <p>Once you’ve logged into your DreamFactory Services Platform (DSP), you’ll need to configure your connection to MongoHQ. Make sure to <a href="https://www.dreamfactory.com/user/register">sign up for a DreamFactory account</a> if you don’t already have one. </p> 
               <h2>Set Up a MongoHQ Service</h2> 
               <p>Once you’re logged into your DSP as an administrator, start by clicking on the ‘Services’ tab on the left-hand side of the screen.</p> 
               <p><img id="img-1380909709522" src="//staticassets.dreamfactory.com/images/services_nav.png?t=1527092313664" alt="services nav" border="0"></p> 
               <p>Then click to Create New Service and fill out the required information about your MongoHQ database. See the screenshot below for an example.</p> 
               <p>Make sure to select ‘NoSQL DB’ in the Type list box and ‘MongoHQ’ in the NoSQL Type list box. You’ll then need to enter your MongoHQ connection string, database name, database username, and database password. Don’t forget to click the Save button at the bottom of the screen.</p> 
               <p><img id="img-1380931620416" src="//staticassets.dreamfactory.com/images/mongohq_setup1-resized-600.png?t=1527092313664" alt="describe the image" border="0"></p> 
               <h2>Browse the REST API for MongoHQ</h2> 
               <p>Once you’ve saved your MongoHQ connection settings, DreamFactory automatically creates a REST API for your MongoHQ database. To browse the API, just click on the ‘API Documentation’ tab on the left-hand side of the screen.</p> 
               <p><img id="img-1380931614416" src="//staticassets.dreamfactory.com/images/api_nav.png?t=1527092313664" alt="api nav" border="0"></p> 
               <p>Then find the API name that you used for MongoHQ (in our example we called the API ‘mongohq’ in the setup screen). You’ll see a total of 14 API calls that allow you to manipulate your MongoHQ data with standard GET, POST, PATCH, PUT, and DELETE verbs.</p> 
               <p><img src="//staticassets.dreamfactory.com/images/mongohq_api-resized-600.png?t=1527092313664" alt="mongohq api resized 600" border="0"></p> 
               <p>We use a great tool called Swagger for our API docs, which makes it really easy to interact with the API and inspect your MongoHQ data right from your web browser. We suggest taking a look at the live Swagger API before writing client-side code to access MongoHQ data from your app.</p> 
               <p>For example, we have a collection called 'zips' that contains demographic data by zipcode. Let’s say we want to run a simple filter on this data to look at cities in California with a population greater than 50,000. In this example, we’ll also limit the number of records returned to 5.</p> 
               <p>Doing so is easy. In the API docs, just navigate to the GET request for /mongohq/{table_name}. Then simply enter the name of the ‘zips’ collection, a simple filter string, and set the limit to 5.  </p> 
               <p><img src="//staticassets.dreamfactory.com/images/mongohq_params-resized-600.png?t=1527092313664" alt="mongohq params resized 600" border="0"></p> 
               <p>Now click the ‘Try it out!’ button and you’ll see the API request and response.</p> 
               <p><img src="//staticassets.dreamfactory.com/images/mongohq_json-resized-600.png?t=1527092313664" alt="mongohq json resized 600" border="0"></p> 
               <p>You can also make API calls from the command line. For example, you can use cURL to make a GET request on a particular MongoHQ table and append a BSON filter string in the request. You’ll see the corresponding JSON returned in the response.</p> 
               <p>And you can see the available MongoHQ API operations right in your browser using the DreamFactory Javascript SDK (for example with FireBug). </p> 
               <p><img id="img-1380932434548" src="//staticassets.dreamfactory.com/images/mongohq_firebug-resized-600.png?t=1527092313664" alt="mongohq firebug resized 600" border="0"></p> 
               <h2>Set Up CRUD Permissions to MongoHQ by User Role</h2> 
               <p>Lastly, if your application requires different data permissions for different user roles, you can easily configure CRUD access for your various MongoHQ collections.</p> 
               <p>For example, let’s say we have a ‘sales rep’ role and we only want to grant READ and WRITE access to a collection called ‘opportunities.’ We don’t want to allow a ‘sales rep’ user to be able to access other collections and we don’t want a ‘sales rep’ user to create or delete data in the ‘opportunities’ collection.</p> 
               <p>Setting up data access permissions only takes a few seconds. In this example, you’d simply create a Role called ‘sales rep.’ Then you’d click on the Roles tab on the left-hand side of the screen and assign ‘Read and Write’ service access to opportunities for the MongoHQ service that we just set up. That’s it!</p> 
               <p><img src="//staticassets.dreamfactory.com/images/mongohq_roles.png?t=1527092313664" alt="mongohq roles" border="0"></p> 
               <p><img src="//staticassets.dreamfactory.com/images/mongo_hq_crud1-resized-600.png?t=1527092313664" alt="describe the image" border="0"></p> 
               <h2>Conclusion</h2> 
               <p>We hope this quick tutorial shows how easy it is to set up MongoHQ in your DSP and access your data with REST and highly configurable CRUD permissions.</p> 
               <p>Please let us know what you think in the comments section!</p> 
              </div>