Docs Menu

Docs HomeRealm

Unidirectional Data Sync - .NET SDK

On this page

  • Overview
  • Sync Data Unidirectionally from a Client Application

New in version 10.17.0.

You can use Asymmetric Sync to stream data from a client application to a Flexible Sync-enabled Atlas App Services App.

For example, you might want to sync data unidirectionally in IoT applications, such as a weather sensor sending data to the cloud. Asymmetric sync 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.

Asymmetric Sync is optimized to provide performance improvements for heavy client-side insert-only workloads.

Important

You cannot query, modify, or delete Asymmetric objects from a client app. Because AsymmetricObject can not be modified by the client, the compiler will not let you add a subscription to an AsymmetricObject.

The .NET SDK allows you to work with Asymmetric objects and standard Realm objects within the same realm.

Before you set up Asymmetric sync, you need to understand the following rules:

  • The C# objects that you will sync with Atlas must derive from the AsymmetricObject class.

  • An object that derives from AsymmetricObject can contain EmbeddedObject types, but not RealmObject types or other AsymmetricObject types.

  • RealmObject and EmbeddedObject types cannot contain AsymmetricObject types as properties.

  • Unidirectional Sync requires Flexible Sync.

The process for syncing data asymmetrically is the same as standard bi-directional sync, as long as the rules above are followed. The following code shows creating an Asymmetric object and syncing it with the backend. It also shows to queries that generate errors.

private class Measurement : AsymmetricObject
{
[PrimaryKey, MapTo("_id")]
public Guid Id { get; private set; } = Guid.NewGuid();
public double Value { get; set; }
public DateTimeOffset Timestamp { get; private set; } = DateTimeOffset.UtcNow;
}
public void SendMeasurementToRealm()
{
var measurement = new Measurement
{
Value = 9.876
};
realm.Write(() =>
{
realm.Add(measurement);
});
// The following line will cause a compile time error
// _ = realm.All<Measurement>();
// The following line will compile but throw a
// Realms.Exceptions.RealmInvalidObjectException at runtime
// _ = measurement.Value;
}
←  Convert Between Non-Synced Realms and Synced Realms - .NET SDKUse Realm in a Console App - .NET SDK →
Share Feedback
© 2023 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.