Puede usar Ingesta de datos para transmitir datos desde la aplicación cliente a una aplicación Atlas App Services habilitada para Flexible Sync.
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
Definir un objeto asimétrico
La ingesta de datos y los objetos asimétricos requieren sincronización flexible. Para definir un objeto asimétrico, pase ObjectType.asymmetricObject a @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
Para transmitir datos desde el cliente a su aplicación backend, debe conectarse a un backend de App Services y autenticar a un usuario.
final appConfig = AppConfiguration(appId); final app = App(appConfig);
final anonCredentials = Credentials.anonymous(); await app.logIn(anonCredentials);
Abrir un reino
Después de tener un usuario autenticado, abre un realm sincronizado.
final currentUser = await app.logIn(credentials); final config = Configuration.flexibleSync(currentUser, [Tricycle.schema], path: 'flex.realm'); final realm = Realm(config);
A diferencia de la sincronización bidireccional, Data Ingest no utiliza una suscripción Flexible Sync.
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 gestiona completamente el ciclo de vida de estos datos. Se mantiene en el dispositivo hasta que la sincronización de Data Ingest se completa y luego se elimina del dispositivo.