Skip to main content
Solved

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


lakshmi_narayanan_t
Discovered Fame

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

@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.

 

 

 

View original
Did this topic help you find an answer to your question?

3 replies

Bikram
Headliner
Forum|alt.badge.img+1
  • Headliner
  • 486 replies
  • May 5, 2023

@lakshmi_narayanan_t 

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.

count=0

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

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

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

 


saleempothiwala
Headliner
Forum|alt.badge.img

@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.

 

 

 


Bikram
Headliner
Forum|alt.badge.img+1
  • Headliner
  • 486 replies
  • May 8, 2023

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


Reply