Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have data in source (mongoDB) which i'm trying to read and print using tLogRow.
I'm storing data into mongo as follow ,
{
"_id" : "ANY-UUID-HERE",
"name" : "test"
}
If I look on mongoDB then it have following record
{
"_id" : BinData(3,"lUUL1Ak/Fj8h4fphNR19tw=="),
"name" : "test"
}
while loading into Talend , it is showing as follow
_id = org.bson.types.Binary@c3bf9cd8
"name" : "test"
where as the datatype is String for the field "_id".
I am not getting any way to convert this into Talend (have tried few ways in Java but didn't worked.). I just know we can do it in tJavaRow.
Any help would be appreciated thanks.
Hello,
I'm not a MongoDB expert, however I have an explanation for the following output you see:
org.bson.types.Binary@c3bf9cd8
What happens in the background is that there's no .toString() implementation that would provide a String representation of the object. Instead what you see is:
This object that you called .toString() on is:
Type X
It's short ID inside the JVM is: Y.
Thus it results in X@Y
What one needs to do in this case is: Understand what functions the object itself provide. This depends on the SDK version one uses lets suppose your job uses 3.6: https://mongodb.github.io/mongo-java-driver/3.6/javadoc/org/bson/types/Binary.html
As you can see it provides a .getData() that is byte[] and I guess you'd have to convert it to a Base64 representation to get back the original string.
Have you tried to use the "dynamic" approach of Talend? By providing a single column in the schema and setting the columns DB Name as * talend should return the raw JSON object, maybe this will be helpful?
Cheers,
Balázs
Hi ,
Thanks for detailed explanation. I haven't tried dynamic approach yet. Let me try this and get back to you.