MongoDB Sync Connector
Bi-directional Synchronization with MongoDB.
Last updated
Bi-directional Synchronization with MongoDB.
Last updated
ObjectBox Sync can synchronize data with MongoDB using the integrated MongoDB Sync Connector. This way, changes made in on ObjectBox Sync clients are synchronized to MongoDB and vice versa.
At this point, the Mongo Sync Connector is available to selected customers only. Join the waitlist here.
ObjectBox Sync brings your data in MongoDB to the edge (e.g. mobile and IoT devices, big and small servers) and synchronize changes back to MongoDB. By using ObjectBox Sync, you can make your MongoDB data always available: continue to work offline and sync in real-time when online.
We likely don't have to mention this, but just to be on the safe side... Do not connect to your MongoDB production instance. Use an instance for testing purposes only.
Configuring the MongoDB Sync Connector involves the following steps:
Set up the ObjectBox Sync Server without MongoDB Sync Connector and validate it runs and actually syncs data. See the Sync Server configuration for details.
Ensure that your MongoDB instance is a replica set. This is required for the MongoDB Sync Connector to work.
Provide the MongoDB configuration, e.g. the connection URL, to the Sync Server and restart it. This can be done via CLI arguments or the JSON configuration file (see below).
Use the Admin UI to verify the MongoDB connection.
In general, the ObjectBox Sync server requires a data model to be provided (see the general sync server documentation). This data model is also used by the MongoDB Sync Connector to map data between ObjectBox and MongoDB. The types of the data model are mapped to MongoDB collections. Similarily, the properties of a type are mapped keys inside a MongoDB document. Thus, ensure that the data model matches the MongoDB schema.
Note: nested documents are supported via the ObjectBox "Flex" property type, which can hold a map-like (JSON-like) structure. We are also considering alternatives to this, so let us know if you have specific requirements.
Only MongoDB replica set instance provide the necessary features for the MongoDB Sync Connector to work (e.g. MongoDB's change streams). Note that all MongoDB Atlas clusters are already replica sets, so you are good to go with them.
Local standalone MongoDB instances (MongoDB Community Edition is fine) can be converted to replica sets. You can do this either by following the official MongoDB documentation, or by following these simplified steps (tested on Ubuntu Linux) for a single node setup:
Stop the MongoDB service: sudo systemctl stop mongod
Edit the MongoDB configuration file: sudo vi /etc/mongod.conf
Add the following lines to the configuration file:
Start the MongoDB service: sudo systemctl start mongod
Connect to the MongoDB shell: mongosh
Initialize the replica set via the MongoDB shell: rs.initiate()
If you prefer to configure the MongoDB Sync Connector via CLI arguments, you can use the following options:
--mongo-url
: - The MongoDB connection string (URL/URI).
--mongo-db
: - The primary MongoDB database name; the "database" containing the collections.