Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

MongoDB Collection update

I am fairly new to Talend and working on a POC.

I want to append a portion of mongo field-value to an existing document via Talend job. Currently I am using tMongoDBInput ----iterate-->> tJavaRow --> tMongoDBOutput

MongoDBInput reads the following field:

"TRIPLE" : {
            "1395633600000" : "160.182",
            "1395720000000" : "170.343"
        }

I want to add more values to this collection and store it back to the same document, but my flow doesn't add the values to the collection. What is the best approach for my use case?

 

Here is my tJavaRow code snippet:

Map<String, String> tripleMap = (Map)input_row.TRIPLE;
Map<String, String> dataTripleMap = (Map)globalMap.get("triple");
TreeMap<String, String> tMap = new TreeMap();
tMap.putAll(tripleMap);
tMap.putAll(dataTripleMap);
output_row.TRIPLE = tMap;

 

Thanks.

Labels (4)
2 Replies
Anonymous
Not applicable
Author

Hello,

Do you want to update particular element in existing document instead of update the whole document? For the update document in MongoDB, Talend have the component called tMongoDBRow.

Best regards

Sabrina

 

Anonymous
Not applicable
Author

That's correct. I want to update specific fields and not all, in the Mongo document. An update could be something like this:

Original document:
{
"created": ISODate("2018-10-04T14:22:55.527Z"),
"modified": ISODate("2018-10-04T14:22:55.527Z"),
"TRIPLE" : {
"1395633600000" : "160.182",
"1395720000000" : "170.343"
}
}

Updated document:
{
"created": ISODate("2018-10-04T14:22:55.527Z"),
"modified": ISODate("2018-10-16T16:19:25.327Z"),
"TRIPLE" : {
"1395633600000" : "160.182",
"1395689700000" : "155.820",
"1395720000000" : "170.343"
}
}

The highlighted/underlined fields are modified as part of tMongoDBOutput with 'upsert with set' option.