我正在尝试在WSO2EI中创建一个mongo数据服务。目前我有这个查询,它给出了基于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>
但是我需要动态输入参数,以便能够 .find 根据我提供的参数名称得到不同的结果,如下所示:
<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>
这可能吗?或者我是否必须为每个参数创建多个查询?
由于
答案 0 :(得分:2)
是的,这是可能的!试试这个(为我工作)。
<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>
示例,
?par1=componentId&par2=pippo
?par1=componentName&par2=proxy_hl7