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
/ /
Sync Data

Transmitir datos a Atlas - C++ SDK

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

Puede sincronizar datos unidireccionalmente cuando declara el esquema de un objeto como REALM_ASYMMETRIC_SCHEMA.

struct WeatherSensorReading {
realm::primary_key<realm::object_id> _id{realm::object_id::generate()};
std::string deviceId;
double temperatureInFahrenheit;
int64_t windSpeedInMph;
};
REALM_ASYMMETRIC_SCHEMA(WeatherSensorReading, _id, deviceId,
temperatureInFahrenheit, windSpeedInMph)

For more information on how to define a REALM_ASYMMETRIC_SCHEMA, including limitations when linking to other object types, see: 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.

auto appConfig = realm::App::configuration();
appConfig.app_id = APP_ID;
auto app = realm::App(appConfig);
auto user = app.login(realm::App::credentials::anonymous()).get();
3

After you have an authenticated user, you can open a synced realm using a flexibleSyncConfiguration(). Unlike opening a realm for non-asymmetric object types, when you open a realm for Data Ingest, you must specify the asymmetric_object types you want to sync.

auto syncConfig = user.flexible_sync_configuration();
auto realm = realm::open<realm::WeatherSensorReading>(syncConfig);

Unlike bidirectional Sync, Data Ingest does not use a Flexible Sync subscription.

Tip

Mixed Object and Asymmetric Object Types

You cannot read, query, or delete an asymmetric_object from a realm, so asymmetric objects are incompatible with bi-directional Flexible Sync or local realm use. You cannot open a single synced realm to manage both regular objects and asymmetric objects - you must use different realms to manage these different object types.

4

Once you have an open realm, you can create an asymmetric_object and set its values as you would a regular object. However, you cannot read or delete these objects. Once created, they sync to the App Services backend and the linked Atlas database.

auto weatherSensorReading =
realm::WeatherSensorReading{.deviceId = "WX1278UIT",
.temperatureInFahrenheit = 64.7,
.windSpeedInMph = 7};
realm.write([&] { realm.add(std::move(weatherSensorReading)); });

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

Establecer el nivel de registro del cliente de sincronización

En esta página