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">{
"Documents": {
"Document": [
{
"Data": "$document"
}
]
}
}</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">{
"Documents": {
"Document": [
{
"Data": "$document"
}
]
}
}</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
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,
?par1=componentId&par2=pippo
?par1=componentName&par2=proxy_hl7