wso2wso2-integration-studio

Conversion error when converting an integer field from mongo to Json format as result in WSO2 Integration Studio


In WSO2 Integration Studio Data Service project, I am extracting data from mongo database using find query. While showing an integer field in json format, I get the following error. I have a field called 'RoomCount' and an integer type that returns a Mongo query result. I am getting error while converting this field to Json Format as below. When I am pulling string type data its work but integer,double.. doesnt work !

 <query id="MunicipalBuildingDetails" useConfig="MongoDb">
    <expression>collectionName.find()</expression>
    <result outputType="json" escapeNonPrintableChar="true">{
  Result:
  {
      Data:
      [{
          "Col1":"$document.RoomCount"
       }
      ]
  }
}</result>
  </query>

Error is;

DS Fault Message: Error occurred when retrieving data. :JSONObject["RoomCount"] not a string.

How can I solve this?


Solution

  • This is another issue with the Mongo JSON conversion implementation. The values are always read as Strings. If you have any Integers rather than reading the element return the complete response and let the client handle it or handle it in the integration layer.

     <query id="MunicipalBuildingDetails" useConfig="MongoDb">
        <expression>collectionName.find()</expression>
        <result outputType="json" escapeNonPrintableChar="true">{
      Result:
      {
          Data:
          [{
              "Col1":"$document"
           }
          ]
      }
    }</result>
      </query>
    

    Another alternative is to use the MongoDB connector. Also I'm not sure whether there is any option in MongoDB to always return values as Strings, may be worth checking that option as well.