Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


This tutorial will guide you on how to expose data from a MongoDB datasource as an OData service using the ESB profile of WSO2 Enterprise Integrator (WSO2 EI).

Follow the steps given below. Also, see the samples in Data Integration Samples/wiki/spaces/EI6xx/pages/49616348.

Table of Contents

Install and start MongoDB 

...

  1. Download the product installer from here, and run the installer.

    Insert excerpt
    Installing the Product
    Installing the Product
    nopaneltrue

  2. Start the ESB profile:

    Panel
    borderColor#542989
    bgColor#ffffff
    borderWidth1
    Localtabgroup
    Localtab
    activetrue
    titleOn MacOS/Linux/CentOS

    Open a terminal and execute the following command:

    Code Block
    wso2ei-6.4.0-integrator
    Localtab
    titleOn Windows
    Go to Start Menu -> Programs -> WSO2 -> Enterprise Integrator 6.4.0 Integrator. This will open a terminal and start the ESB profile.
  3. Log in to the management console of ESB profile of WSO2 EI using the following URL on your browser:  "https://localhost:9443/carbon/".
  4. Click Create under the Data Service menu to open the Create Data Service window.
  5. Enter the following data service name.

    Data Service NameMongoDB
  6. Leave the default values for the other fields.
  7. Click Next to go to the Datasources screen

...

  1. Click Add New Query, and enter the following data:

    Query IDEnter mongo_find as the query ID.
    DatasourceSelect the datasource for which you are going to write a query. Select the mongo datasource that you created previously.
    SPARQL

    In this field, enter the SPARQL query describing the data that should be retrieved from the MongoDB datasource. We will use the following query: 

    Code Block
    things.find()
  2. Define Output Mapping: Now, let's specify how the data fetched from the datasource should be displayed in the output. We will create output mappings for the Data field.
    1. Start by giving the following information:

      Output typeSpecify the format in which the query results should be presented. You can select XML, JSON or RDF. We will use XML for this tutorial.
      Grouped by elementSpecify a grouping for all the output mappings. This will be the XML element that will group the query result. Enter Documents in this field. 
      Row NameSpecify the XML element that should group each individual result. Enter Document in this field.
    2. Click Add New Output Mapping to start creating the output mapping. Enter the following values:
    3. Click Main Configuration to return to the Query screen.

  3. Save the query, and click Next to go to the Operations screen.

...

Code Block
https://localhost:8243/odata/{data_service_name}/{data_source_id}/{table_name}('_id')

DELETE https://localhost:8243/odata/MongoODataSampleService/MongoID/PROJECT('5c29b6f577ec332a94d8fecc')

Accept: application/json

Content-Type: application/json

{ "location" : ”Kandy” }


To invoke a particular query, send the HTTP request as shown below. In this example, we are going to retrieve the id and name of all the projects.

Code Block
https://localhost:8243/odata/{data_service_name}/{data_source_id}/{table_name}?$select={attribute_name_1, attribute_name_2}


GET https://localhost:8243/odata/MongoODataSampleService/MongoID/project?$select=name,id

Accept: application/json

...