Docs Menu
Docs Home
/ /
Atlas Device SDKs
/ /

Stream Data to Atlas - C++ SDK

On this page

  • Sync Data Unidirectionally from a Client Application
  • Define an Asymmetric Object
  • Connect and Authenticate with an App Services App
  • Open a Realm
  • Create Asymmetric Objects

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.

1

You can sync data unidirectionally when you declare an object's schema as a 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

To stream data from the client to your backend App, you must connect to an App Services backend and authenticate a user.

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 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.

Back

Set the Sync Client Log Level

Next

Logging