[resolved] JSON format in tMongoDBOutput

One Star

[resolved] JSON format in tMongoDBOutput

Hi,
I was looking at this document.
https://help.talend.com/search/all?query=tMongoDBOutput&content-lang=en
I am not able to understand how exactly to use data node and query node here. 
Also, the tMongoDBOutput component requires the schema to be same as input schema.
I have the input coming from a sql schema as:
 Name, DOB, class, subject1_marks, subject2_marks,subject3_marks, average_marks
I want to frame a json in my mongoDB like:
{
 _id:{ name:"abc", DOB:"26-01-1947"},
subjects:
}
Also i want to perform upsert operations where i can update marks for specific subjects and add additional fields like 
{
 _id:{ name:"abc", DOB:"26-01-1947"},
subjects:
}
How to do this?
I see upsert option but am not able to use it. Also how to use properties of mongo like $push and $set here.

Thanks!

Accepted Solutions
Community Manager

Re: [resolved] JSON format in tMongoDBOutput

Hi
The data node and the query node have to be defined in the json tree, the data node defines the data will be updated or inserted, the query node defines the query condition. In the below example, the id element is defined under the query node, it will compare the input id value with existing ids in target database, if id already exists, then update the data, otherwise, insert a new data.


Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

All Replies
Community Manager

Re: [resolved] JSON format in tMongoDBOutput

Hi
The data node and the query node have to be defined in the json tree, the data node defines the data will be updated or inserted, the query node defines the query condition. In the below example, the id element is defined under the query node, it will compare the input id value with existing ids in target database, if id already exists, then update the data, otherwise, insert a new data.


Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business