[
https://issues.apache.org/jira/browse/NIFI-4989?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16403990#comment-16403990
]
ASF GitHub Bot commented on NIFI-4989:
--------------------------------------
Github user MikeThomsen commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2560#discussion_r175286257
--- Diff:
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java
---
@@ -96,6 +99,125 @@ public void testValidators() {
Assert.assertEquals(0, results.size());
}
+ @Test
+ public void testQueryAndUpdateKey() {
+ runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "_id");
+ runner.setProperty(PutMongo.UPDATE_QUERY, "{}");
+ runner.assertNotValid();
+ }
+
+ @Test
+ public void testNoQueryAndNoUpdateKey() {
+ runner.removeProperty(PutMongo.UPDATE_QUERY);
+ runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "");
+ runner.assertNotValid();
+ }
+
+ @Test
+ public void testBlankUpdateKey() {
+ runner.setProperty(PutMongo.UPDATE_QUERY_KEY, " ");
+ runner.assertNotValid();
+ }
+
+ @Test
+ public void testUpdateQuery() {
+ Document document = new Document()
+ .append("name", "John Smith")
+ .append("department", "Engineering");
+ collection.insertOne(document);
+ String updateBody = "{\n" +
+ "\t\"$set\": {\n" +
+ "\t\t\"email\": \"[email protected]\",\n" +
+ "\t\t\"grade\": \"Sr. Principle Eng.\"\n" +
+ "\t},\n" +
+ "\t\"$inc\": {\n" +
+ "\t\t\"writes\": 1\n" +
+ "\t}\n" +
+ "}";
+ Map<String, String> attr = new HashMap<>();
+ attr.put("mongo.update.query", document.toJson());
+ runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "");
+ runner.setProperty(PutMongo.UPDATE_MODE,
PutMongo.UPDATE_WITH_OPERATORS);
+ runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE);
+ runner.setProperty(PutMongo.UPDATE_QUERY, "${mongo.update.query}");
+ runner.setValidateExpressionUsage(true);
+ runner.enqueue(updateBody, attr);
+ updateTests(document);
+ }
+
+ @Test
+ public void testUpdateBySimpleKey() {
+ Document document = new Document()
+ .append("name", "John Smith")
+ .append("department", "Engineering");
+ collection.insertOne(document);
+ String updateBody = "{\n" +
+ "\t\"name\": \"John Smith\",\n" +
+ "\t\"$set\": {\n" +
+ "\t\t\"email\": \"[email protected]\",\n" +
+ "\t\t\"grade\": \"Sr. Principle Eng.\"\n" +
+ "\t},\n" +
+ "\t\"$inc\": {\n" +
+ "\t\t\"writes\": 1\n" +
+ "\t}\n" +
+ "}";
+ runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "name");
+ runner.setProperty(PutMongo.UPDATE_MODE,
PutMongo.UPDATE_WITH_OPERATORS);
+ runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE);
+ runner.setValidateExpressionUsage(true);
+ runner.enqueue(updateBody);
+ updateTests(document);
+ }
+
+ @Test
--- End diff --
Yeah. I'm adding 2 at the moment. One for update by keys and one for query.
> PutMongo cannot specify nested fields or multiple lookup keys
> -------------------------------------------------------------
>
> Key: NIFI-4989
> URL: https://issues.apache.org/jira/browse/NIFI-4989
> Project: Apache NiFi
> Issue Type: Improvement
> Reporter: Mike Thomsen
> Assignee: Mike Thomsen
> Priority: Major
>
> From the user mailing list:
> {quote}{color:#222222}I am using PutMongo processor to update documents in a
> mongoDB collection.{color}
> {color:#222222}I would like to specify nested field and multiple key in the
> update Key.{color}
> {color:#222222}For exemple :{color}
> {color:#222222}- my mongodb documents are {"nom":"HAMEL",
> "prenom":"Yves",{color}
> {color:#222222}"ids":\{"idSoc":"1234", "idInterne":"788"}}{color}
> {color:#222222}- I would'd like to set update query key to something like
> {"ids.idSoc" ,{color}
> {color:#222222}"nom"}{color}
> {color:#222222}- this would means that I update document with ids.idSoc and
> nom equals to{color}
> {color:#222222}my mew document.{color}
> {quote}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)