Mule消息丰富了对MongoDB的查询

时间:2014-05-22 10:00:39

标签: mongodb mule

嘿,这是我在这里发表的第一篇文章,感谢您的帮助:)。

我正在尝试创建一个流(使用Mule),它将一些csv文件读取并转换为通用格式(此部分可用)。之后我想用MongoDB中的3个对象来丰富我的消息。我想我可以通过使用我的有效负载中的一个属性来实现这一点,例如Payload.MeterUID来查找MongoDB中的文档_id,然后使用3个给定的_id个对象来丰富我的主要信息。

到目前为止,这是我的enricher

 <enricher doc:name="Message Enricher">
        <mongo:find-objects config-ref="Mongo_DB1" collection="GSMdata" doc:name="Mongo DB">
        <mongo:query-attributes>
        <mongo:query-attribute key="MeterUID">#[payload.MeterUID]</mongo:query-attribute>
    </mongo:query-attributes>
            <mongo:fields ref="#[payload]"/>
        </mongo:find-objects>
    </enricher>

如何完成此enricher以便它以我描述的方式工作,如果可能的话? 在这一点上任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

您的配置存在一些问题,其中之一就是您并未真正说明 您希望如何丰富您的信息。

首先,使用mongo:query-attributes,您需要使用mongo:find-objects-using-query-map,而不是mongo:find-objects

其次,对于mongo:fields,您需要一个要在查询中返回的字段列表,而不是对消息有效负载的引用。如果您只需要_id字段,那么只需使用

即可
<mongo:fields>
    <mongo:field>_id</mongo:field>
</mongo:fields>

第三,丰富者需要知道它应该如何丰富信息。您是在地图有效负载中设置新字段,还是在某些属性或变量中设置?假设您有一个地图有效负载,您可以将其指定为<enricher target="#[payload.my_mongo_id_list]" doc:name="Message Enricher">

所以,一起:

<enricher target="#[payload.my_mongo_id_list]" doc:name="Message Enricher">
    <mongo:find-objects-using-query-map config-ref="Mongo_DB1" collection="GSMdata" doc:name="Mongo DB">
        <mongo:query-attributes>
            <mongo:query-attribute key="MeterUID">#[payload.MeterUID]</mongo:query-attribute>
        </mongo:query-attributes>
        <mongo:fields>
            <mongo:field>_id</mongo:field>
        </mongo:fields>
    </mongo:find-objects-using-query-map>
</enricher>