write data into mysql from mongodb how to handle auto increment column

Userlevel 2

When migrating data from MongoDB to MySQL, I noticed that there is no 'id' column in MongoDB, but there is an 'id' column in MySQL. As a result, I am facing issues when writing data into MySQL. I am looking for assistance in handling the auto-increment column in this scenario. Can anyone provide any guidance or assistance?

Additionally, I am exploring the possibility of using the JDBC Tee processor to handle this situation. Could you please advise me on how to use the JDBC Tee processor in this scenario?


Best answer by saleempothiwala 5 May 2023, 22:22

View original

3 replies

Userlevel 5
Badge +1


That we can do it in jython evalualtor.

After taking data from mongoDB  , toy can introdcue jython evaluator to create id by using the code snippet.


You set the initial value of Id as per your need.


def incr():
global count
count += 1
return count

# Sample Jython code
for record in sdc.records:
s1 = incr()
record.value['id'] = s1
# Write record to processor output

except Exception as e:
# Send record to error
sdc.error.write(record, str(e))


Userlevel 4

@Bikram , every time the pipeline runs, it will start the count with 0. So if there is a PK on the table, it will fail.

@lakshmi_narayanan_t Try using JDBCTee processor.




Userlevel 5
Badge +1

May I know did you manage it using jdbc tee processor , if yes please provide details for future reference for others.