Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
Device Sync - Flutter SDK

Transmisión de datos a Atlas - SDK de Flutter

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.

1

La ingesta de datos y los objetos asimétricos requieren sincronización flexible. Para definir un objeto asimétrico, pase ObjectType.asymmetricObject a @RealmModel().

@RealmModel(ObjectType.asymmetricObject)
class _WeatherSensor {
@PrimaryKey()
@MapTo("_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.

2

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);
3

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.

4

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.

Volver

Set Sync Log Level

En esta página