Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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
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.