Search code examples
mongodbwso2wso2-integration-studio

How to read data from MongoDB query result as Json Format in WSO2 Integration Studio Data Service Project?


I created mongo database as data service in Integration Studio. I want to call a query from Mongo and read its result as Json. I am trying below method but data is coming as null. I want to read the data returned by Mongo in json format. Can you help with this ?

The Code for Integration Studio Data service xml:

enter image description here

Data returned by MongoDb Query:

[
  {
    "_id": {
      "id": "1234",
      "type": "test"
    }
  }
]

Solution

  • Update your output mappings to the following.

    {
      "Documents": {
        "Document": [
          {
            "id": "$document._id.id",
            "name": "$document._id.type"
          }
        ]
      }
    }