How to Integrate with MongoDB using Open Source RESTHeart Library

Document created by akhil_khandelwal Employee on Mar 5, 2016Last modified by Adam Arrowsmith on Mar 7, 2016
Version 4Show Document
  • View in full screen mode

In this article, we have covered a possible approach to integrate Boomi Atomsphere with MongoDB using RESTHeart service. RESTHeart provides a REST interface to interact with MongoDB using JSON over HTTP.

 

 

Overview

MongoDB is one of the most prominent NoSQL databases. It works on the concept of documents and collections. A document is a set of key-value pairs. MongoDB's documents are encoded in a JSON-like format, called BSON (binary JSON). A collection is a group of MongoDB documents. More details can be found on MongoDB’s website.

 

While there are number of interfaces and tools available for integrating with MongoDB, we will be using the RESTHeart API because it provides a lightweight REST interface, easy setup, and high performance. The RESTHeart API enables CRUD operations on MongoDB’s document and collections. With AtomSphere’s HTTP Connector it’s easy to model the CRUD methods provided by the API.

 

Installation and Prerequisites

This example requires following setup related activities:

 

RESTHeart API Tutorial and API Reference

 

For this POC, I already created a database (dev) and a collection (employees) in MongoDB which would be used to create and query documents from Boomi process

 

Scenario 1 – Insert/Update an Employee record in Employees collection using POST

POST /<dbname>/<collname>

creates or updates a document in the collection <collname> of the db <dbname>

  • POST has upsert semantic: if the document exists it will be updated, otherwise it will be created.
  • The document id can be specified with the optional property _id; otherwise an _id will be created
  • Optimistic concurrency control via ETag (entity tag) is required.

 

 

For updates, it’s mandatory to provide ETag (https://softinstigate.atlassian.net/wiki/display/RH/ETag) in a HTTP header If-Match. If not passed, server returns HTTP 409 with ETag in the header for the conflicting document.

 

 

JSON Profile for the Object:

 

 

Process:

 

Branch 1 attempts to insert a document. If there is a conflict (HTTP 409 response), then it saves ETag and use it in Branch 2 for Update

 

Scenario 2 – Querying document based on a filter

GET /<dbname>/<collname>

This returns the HAL representation of the collection <collname> of db <dbname> with its documents as embedded resources

  • Paging supported.
  • Sorting supported.
  • Filtering supported.
  • ETag based caching supported (entity tag).
  • Eager db cursors preallocation supported. Dramatically improves read performances on big collections.

 

 

 

 

 

Note – Before Sending to connector filter in the URI should be encoded (http://www.w3schools.com/jsref/jsref_encodeURI.asp)

 

1 person found this helpful

Attachments

    Outcomes