【问题标题】:Update Operators in Mule MongoDB Cloud ConnectorMule MongoDB 云连接器中的更新操作符
【发布时间】:2014-07-03 19:14:33
【问题描述】:

是否可以在通过 Mule 中的 MongoDB 云连接器执行的更新中使用更新运算符(例如 $set)?我想执行一个 update-objects-using-map 操作来向匹配的对象添加一个字段,这些对象已经存在于我的集合中。 目前,它正在用我要添加的字段替换所有现有字段。我需要添加 $set 运算符来完成我想要的。

这是一个示例配置:

<mongo:update-objects-using-map config-ref="Mongo_DB"    doc:name="Mongo DB"   database="myDatabase" password="myPassword" username="myUser" collection="test_SalesInvoice"   multi="false" upsert="true">
    <mongo:query-attributes>
        <mongo:query-attribute key="Invoice">#[payload.Invoice]</mongo:query-attribute>
    </mongo:query-attributes>
    <mongo:element-attributes >
        <mongo:element-attribute key="Worked">yes</mongo:element-attribute>
    </mongo:element-attributes>
</mongo:update-objects-using-map>

谢谢!

贾斯汀

【问题讨论】:

  • 这里github.com/mulesoft/mongo-connector/blob/… 对$set 进行了更新测试,看来您需要将“$set”作为更新对象传递,您将新字段作为顶级对象传递。这是 $set github.com/mulesoft/mongo-connector/blob/… 的 xml 语法示例
  • 查看示例和测试,看来您需要将其传递给 $set 作为更新的顶级元素: yes 似乎还有一个 update-objects-by-function-using-map 函数为 $set: 没有测试环境所以无法告诉您哪一种适合您。
  • 啊,看来 update-objects-by-function-using-map 可以解决问题!我会做一些更广泛的测试,然后在这里更新。谢谢!
  • 感谢您的回复!初步测试表明 update-objects-by-function-using-map (如此处所建议的)确实是答案,希望这对遇到此问题的其他人有所帮助。但是,我的团队改变了方向,完全追求不同的解决方案,所以我没有更严格地测试这个解决方案。

标签: mongodb mule


【解决方案1】:
<mongo:update-objects-by-function-using-map collection="yourCollection" 
                                                    config-ref="MongoDatabase" doc:name="Update Object"
                                                    upsert="true" function="$set">
            <mongo:query-attributes>
                <mongo:query-attribute key="id">#[payload.id]</mongo:query-attribute>
            </mongo:query-attributes>
            <mongo:element-attributes>
               <mongo:element-attribute key="newField">#[payload.newFieldValue]</mongo:element-attribute></mongo:element-attributes>
        </mongo:update-objects-by-function-using-map>

id  : is the attribute that will match with the original object to be update
newField : its the name of the new attribute that u want to add to u object on mongodb

【讨论】:

  • 虽然您的回答可能会解决问题,但最好能说明问题所在以及您的回答如何解决问题。这是进一步改进这个和未来答案的建议。
  • 感谢您的回复!我不再有环境设置来测试这个解决方案,但我记得的解决方案表明这可能接近我需要的。希望其他人会觉得它有帮助。
  • 问题描述:用户想要更新 mongoDb 上的对象列表 throw Mule ESB,这与使用 SQL 执行 (Update where ..) 完全一样。
猜你喜欢
  • 1970-01-01
  • 2015-06-08
  • 2017-04-09
  • 1970-01-01
  • 2020-03-23
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多