mongodbwso2-data-services-serverwso2-enterprise-integratordataservice

WSO2 Mongo data service dynamic query parameter


i'm trying to create a mongo data service in WSO2EI. Currently I have this query, which gives me results based on componentId:

<query id="find" useConfig="MongoDB">
      <expression>collection.find("{componentId : #}")</expression>
      <result outputType="json">{&#xd;"Documents": {&#xd;"Document": [&#xd;{&#xd;"Data": "$document"&#xd;}&#xd;]&#xd;}&#xd;}</result>
      <param name="componentId" sqlType="STRING"/>
</query>

But I need to enter the parameter(s) dynamically to be able to .find different results based on parameter name I provided, something like this:

<query id="find" useConfig="MongoDB">
      <expression>collection.find("{fieldName : #} : {fieldValue : #}")</expression>
      <result outputType="json">{&#xd;"Documents": {&#xd;"Document": [&#xd;{&#xd;"Data": "$document"&#xd;}&#xd;]&#xd;}&#xd;}</result>
      <param name="fieldName" sqlType="STRING"/>
<param name="fieldValue" sqlType="STRING"/>
</query>

Is this possible? Or do I have to create multiple queries for each parameter?

Thanks


Solution

  • Yes it's possible! Try this (work for me).

    <query id="wesites_find_param" useConfig="mongo_ds">
          <expression>websites.find("{#: #}")</expression>
          <result element="Documents" rowName="Document" useColumnNumbers="true">
             <element column="document" name="Data" xsdType="string"/>
          </result>
          <param defaultValue="name" name="par1" sqlType="STRING"/>
          <param name="par2" sqlType="STRING"/>
       </query>
        <operation name="website_find_param_op">
          <call-query href="wesites_find_param">
             <with-param name="par1" query-param="par1"/>
             <with-param name="par2" query-param="par2"/>
          </call-query>
       </operation>
       <resource method="GET" path="/websitefind">
          <call-query href="wesites_find_param">
             <with-param name="par1" query-param="par1"/>
             <with-param name="par2" query-param="par2"/>
          </call-query>
       </resource>
    

    Example,