Talend Connect
Virtual Summit
JOIN US!
And visit the Customer
& Community Lounge.
May 27-28, wherever you are.

MongoDB Collection update

Highlighted
Four Stars

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.

Highlighted
Moderator

Re: MongoDB Collection update

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

 

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Highlighted
Four Stars

Re: MongoDB Collection update

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.


2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Put Massive Amounts of Data to Work

Learn how to make your data more available, reduce costs and cut your build time

Watch Now

How OTTO Utilizes Big Data to Deliver Personalized Experiences

Read about OTTO's experiences with Big Data and Personalized Experiences

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog