Stream Data to Atlas - Flutter SDK
On this page
You can use Data Ingest to stream data from the client application to a Flexible Sync-enabled Atlas App Services App.
You might want to sync data unidirectionally in IoT applications, such as a weather sensor sending data to the cloud. Data Ingest is also useful for writing other types of immutable data where you do not require conflict resolution, such as creating invoices from a retail app or logging application events.
Data Ingest is optimized to provide performance improvements for heavy client-side insert-only workloads.
Sync Data Unidirectionally from a Client Application
Define an Asymmetric Object
Data Ingest and asymmetric objects require Flexible Sync. To define an
asymmetric object, pass ObjectType.asymmetricObject
to
@RealmModel()
.
(ObjectType.asymmetricObject)class _WeatherSensor { () "_id") ( late ObjectId id; late String deviceId; late double modtemperatureInFahrenheitel; late double barometricPressureInHg; late double windSpeedInMph; }
For more information on how to define an asymmetric object, refer to Define an Asymmetric Object.
Connect and Authenticate with an App Services App
To stream data from the client to your backend App, you must connect to an App Services backend and authenticate a user.
final appConfig = AppConfiguration(appId); final app = App(appConfig);
final anonCredentials = Credentials.anonymous(); await app.logIn(anonCredentials);
Open a Realm
After you have an authenticated user, open a synced realm.
final currentUser = await app.logIn(credentials); final config = Configuration.flexibleSync(currentUser, [Tricycle.schema], path: 'flex.realm'); final realm = Realm(config);
Unlike bi-directional Sync, Data Ingest does not use a Flexible Sync subscription.
You can't query an asymmetric object or persist it in a local realm, so asymmetric objects are incompatible with bi-directional Flexible Sync, Partition-Based Sync, and local Realm use.
Create Asymmetric Objects
Once you have an open Realm, you can create an asymmetric object inside
a write transaction. Pass your object data to realm.ingest
.
realm.write(() { realm.ingest( WeatherSensor(weatherSensorId, "WX1278UIT", 66.7, 29.65, 2)); });
You can't read asymmetric objects. Once created, they sync to the App Services backend and the linked Atlas database.
Atlas Device Sync completely manages the lifecycle of this data. It is maintained on the device until Data Ingest synchronization is complete, and then removed from the device.