你能在 Mule 中一次更新集合中的所有 Mongo 文档吗?
Can you update all Mongo documents in a collection at once in Mule?
我正在尝试用当前日期更新我的 mongoDB 集合中的生效日期。我想更新有效日期为空的集合中的所有文档。
你如何配置变压器来做到这一点?查询引用字段信息消息讨论了一个 Id,元素字段看起来需要一个包含文档的有效负载,该文档将替换正在更新的文档。我只是想更新一个字段,目前我的查询出现错误,但它确实适用于 mongoDB 命令行。
这是我要实现的查询:
db.stores.update({"EffectiveEndDateTime" : null}, {$set : {"EffectiveEndDateTime" : "2017-01-13T18:56:55.257Z"}})
我的 XML 目前在 Mule 中为 Mongo 配置:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd">
<mongo:config name="Mongo_DB__Configuration" username="${mongodb.username}" password="${mongodb.password}" database="${mongodb.database}" host="${mongodb.host}" doc:name="Mongo DB: Configuration"/>
<flow name="deactivateCurrentDocumentsFlow">
<http:listener config-ref="httpListenerConfig" path="/mongo" allowedMethods="POST" doc:name="HTTP"/>
<mongo:update-documents-by-function config-ref="Mongo_DB__Configuration" collection="stores" function="$set : {"EffectiveEndDateTime": "2017-01-13T17:51:08.153Z" }" doc:name="Mongo DB"/>
<object-to-string-transformer doc:name="Object to String"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
我得到的错误:
Message : Failed to invoke updateDocumentsByFunction.
Payload : {NullPayload}
Payload Type : org.mule.transport.NullPayload
Element : /deactivateCurrentDocumentsFlow/processors/0 @ test --------------------------------------------------------------------------------
Root Exception stack trace:
com.mongodb.MongoWriteException: Unknown modifier: $set : {"EffectiveEndDateTime": "2017-01-13T17:51:08.153Z" }
谢谢
您必须使用 Functions 变体的更新文件。
<mongo:update-documents-by-functions config-ref="Mongo_DB"
collection="myCollection" functions="$set,{"key":123}">
</mongo:update-documents-by-functions>
我正在尝试用当前日期更新我的 mongoDB 集合中的生效日期。我想更新有效日期为空的集合中的所有文档。
你如何配置变压器来做到这一点?查询引用字段信息消息讨论了一个 Id,元素字段看起来需要一个包含文档的有效负载,该文档将替换正在更新的文档。我只是想更新一个字段,目前我的查询出现错误,但它确实适用于 mongoDB 命令行。
这是我要实现的查询:
db.stores.update({"EffectiveEndDateTime" : null}, {$set : {"EffectiveEndDateTime" : "2017-01-13T18:56:55.257Z"}})
我的 XML 目前在 Mule 中为 Mongo 配置:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd">
<mongo:config name="Mongo_DB__Configuration" username="${mongodb.username}" password="${mongodb.password}" database="${mongodb.database}" host="${mongodb.host}" doc:name="Mongo DB: Configuration"/>
<flow name="deactivateCurrentDocumentsFlow">
<http:listener config-ref="httpListenerConfig" path="/mongo" allowedMethods="POST" doc:name="HTTP"/>
<mongo:update-documents-by-function config-ref="Mongo_DB__Configuration" collection="stores" function="$set : {"EffectiveEndDateTime": "2017-01-13T17:51:08.153Z" }" doc:name="Mongo DB"/>
<object-to-string-transformer doc:name="Object to String"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
我得到的错误:
Message : Failed to invoke updateDocumentsByFunction.
Payload : {NullPayload}
Payload Type : org.mule.transport.NullPayload
Element : /deactivateCurrentDocumentsFlow/processors/0 @ test --------------------------------------------------------------------------------
Root Exception stack trace:
com.mongodb.MongoWriteException: Unknown modifier: $set : {"EffectiveEndDateTime": "2017-01-13T17:51:08.153Z" }
谢谢
您必须使用 Functions 变体的更新文件。
<mongo:update-documents-by-functions config-ref="Mongo_DB"
collection="myCollection" functions="$set,{"key":123}">
</mongo:update-documents-by-functions>