syncObject method

void syncObject(
  1. String collectionName,
  2. String objectId
)

Manually trigger immediate sync for a specific object.

Use this when you need to force sync without waiting for the automatic change listener. Common scenarios:

  • After batch writes where change listeners may not fire
  • When needsSync predicate is complex and you want explicit control
  • For critical updates that must sync immediately

Sends complete object data (not just diffs) to ensure accuracy.

Example:

// Create and sync a message
realm.write(() {
  final message = ChatMessage('id-123', 'Hello', ...);
  message.syncUpdateDb = true;
  realm.add(message);
});
realmSync.syncObject('chat_messages', 'id-123');

Parameters:

  • collectionName: MongoDB collection name (must match config)
  • objectId: The unique ID of the object to sync

Note: Object must exist in the configured RealmResults for this collection.

Implementation

void syncObject(String collectionName, String objectId) {
  final helper = _helpers[collectionName];
  if (helper == null) {
    AppLogger.log(
      'RealmSync: no helper found for collection $collectionName',
    );
    return;
  }
  AppLogger.log(
    'RealmSync: manually triggering full sync for $collectionName/$objectId',
  );
  helper.scheduleFullSync(objectId);
}