MongoDB offline synchronization

This article provides implementation ideas, configuration examples, and verification methods for MongoDB offline synchronization scenarios, which can be used as a reference for actual project configuration.

Implement offline synchronization of data from the result table to the target table in mongoDB

Case

Offline synchronization of data in t_source to t_target in mongoDB

solution

Create a Flink SQL job type and add the following dependencies

20250109182905

CREATE TABLE from_table(
    _id STRING,
    name STRING,
    age INT,
    city STRING,
    PRIMARY KEY (_id) NOT ENFORCED
) WITH (
    'connector'='mongodb',
    'uri'='mongodb://root:root123@localhost:27017',
    'collection'='t_source',
    'database'='isxcode_db'
);

CREATE TABLE target_table(
    _id STRING,
    name STRING,
    age INT,
    city STRING,
    PRIMARY KEY (_id) NOT ENFORCED
) WITH (
    'connector'='mongodb',
    'uri'='mongodb://root:root123@localhost:27017',
    'collection'='t_sink',
    'database'='isxcode_db'
); 

INSERT INTO target_table select * from from_table;
Configuration itemsillustrate
connectorConnection method
uriDatabase connection url
collectiontable name
database库名