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).

...

  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.6.0-integrator
    Localtab
    titleOn Windows
    Go to Start Menu -> Programs -> WSO2 -> Enterprise Integrator 6.6.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 details:

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

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

    Code Block
    things.insert("{id:#, name:#}")
  2. Now let's specify input mappings for the data in the MongoDB database. We will create output mappings for the id and name fields.

    1. Click Add New Input Mapping to start creating the input mapping. We want to add data into the database using the id and name fields. First, create the input mapping for id.
    2. Click Add to save the input mapping.
    3. Create the input mapping for the name field.

  3. Save the query.

...

  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.
    SPARQLExpression

    In this field, enter the SPARQL query the 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

...