Docs Menu

Docs HomeAtlas App Services

Stream Data Unidirectionally from a Client to Atlas

On this page

  • Set up Atlas Access
  • Create an Atlas App Services App
  • Configure Device Sync and Data Ingest
  • Enable an Authentication Provider
  • Add Sync to the Client Application
  • Connect the client to an App Services backend
  • Authenticate a User
  • Open a Synced Realm
  • Create Asymmetric Objects and Write Data

If you have a mobile or client application that produces a large volume of data you'd like to stream to MongoDB Atlas, you can sync data unidirectionally using Device Sync. We call the feature that enables this unidirectional sync Data Ingest.

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. You cannot read this data from the realm where you're streaming it.

Currently Data Ingest is only available for the following Realm SDKs:

  • C++ SDK

  • .NET SDK

  • Kotlin SDK

  • Node.js SDK

  • React Native SDK

  • Swift SDK

Follow these high-level steps to get started:

1

The App Services application is the gateway that enables your client device to connect to MongoDB Atlas. When you create an App, you name it, link it to an Atlas cluster, and specify the deployment model and deployment region that work best for your application.

To learn how to create an App Services App, see Create an App.

2

Device Sync is the service that synchronizes data to Atlas and across your client devices. Device Sync, together with the Realm SDKs, automatically manages network connectivity, user permissions, and conflict resolution. The App Services app provides the built-in user authentication that Device Sync and the Realm SDKs leverage to secure your data.

When you configure Device Sync, you specify the data source that the client devices can access as well as the permissions that determine what data a user can write.

You can configure Device Sync via the Atlas UI, the Atlas App Services Command Line Interface, or the App Services Admin API. The first time you configure Device Sync, you may find it helpful to use the Atlas UI as it provides links and information about various settings and options.

To enable Data Ingest for one or more collections, you select the collection or collections in the Advanced Configuration section of your Device Sync configuration. Only collections with an App Services Schema are available to select in this drop-down.

If you have not yet created a schema for the collection that you want to sync unidirectionally, you can either:

3

Your client devices must authenticate in order to access synced data. App Services provides several authentication providers, such as email/password or anonymous authentication, to enable your users to authenticate. Configure one or more of these authentication providers to enable authentication in your client application.

You can configure authentication providers within the App Services App UI by selecting Authentication in the left navigation menu, and then click a provider to configure it. You can also configure authentication providers by editing the App Services configuration with the Atlas App Services Command Line Interface, or the App Services Admin API.

After this, you've got everything set up that you need on the Atlas side, and you can prepare your client application to sync data unidirectionally.

1

In your client application code, initialize an App client to connect your client to your App Services backend. This lets your client use App Services features like authentication, and enables opening a synced realm.

2

Your client application user must be authenticated with the App Services backend in order to write synchronized data. Add logic to your client app to register and log in users.

3

Once you have an authenticated user, you can open a synced instance of Realm Database to use for that user. Because Asymmetric Sync is write-only, you cannot define a Flexible Sync query to read data on the device. This differs from bidirectional Flexible Sync, where you would create a query subscription to determine what data to sync to the device.

4

The Realm SDKs provide a special type of object to use with Data Ingest: an Asymmetric Object. Refer to the Realm SDK documentation for details on how to define Asymmetric Objects.

Create and write Asymmetric Objects to a synced realm, and the Realm SDKs use Device Sync manage the process of streaming the data automatically. When the device has a network connection, the SDKs stream data to the App Services backend and into Atlas. When the device does not have a network connection, the data persists on the device and automatically uploads when the network connection is restored.

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.

← Sync Data in a Client Application with Atlas and Other Devices