我正在从称为属性的MongoDB集合中读取。我收到了结果,但我想根据查询参数限制结果。
以下是使用该代码获取集合中所有记录的代码 -
<flow name="readFromMongoDB" doc:name="insertInMongoDB">
<vm:inbound-endpoint exchange-pattern="request-response"
path="mdb-read-data-vm" doc:name="VM" />
<json:json-to-object-transformer
returnClass="java.util.HashMap" doc:name="JSON to Object" />
<logger level="INFO" doc:name="Logger" message=">>>>>>>> #[payload.name]" />
<mongo:find-objects config-ref="Mongo_DB"
collection="attributes" doc:name="Find Attribute">
</mongo:find-objects>
<mongo:mongo-collection-to-json />
<logger level="INFO" doc:name="Logger" />
</flow>
如何提及查询属性以过滤结果?
答案 0 :(得分:0)
我能够使用mongo中的mongo:query-attribute来优化我的搜索:find-one-object-using-query-map
这是工作代码 -
<flow name="readFromMongoDB" doc:name="readFromMongoDB">
<vm:inbound-endpoint exchange-pattern="request-response"
path="mdb-read-data-vm" doc:name="VM" />
<json:json-to-object-transformer
returnClass="java.util.HashMap" doc:name="JSON to Object" />
<logger level="INFO" doc:name="Logger" message=">>>>>>>> #[payload.name]" />
<mongo:find-one-object-using-query-map
config-ref="Mongo_DB" collection="#[collection]" doc:name="Mongo DB">
<mongo:query-attributes>
<mongo:query-attribute key="name">#[payload.name]</mongo:query-attribute>
</mongo:query-attributes>
</mongo:find-one-object-using-query-map>
<mongo:dbobject-to-json doc:name="Mongo DB"/>
<logger level="INFO" doc:name="Logger" message= "#[payload]" />
</flow>