From 24dce6050e2f879180df287ed9f0e2bdf464e9d7 Mon Sep 17 00:00:00 2001 From: cbullinger Date: Wed, 9 Aug 2023 07:08:51 -0400 Subject: [PATCH] Apply review feedback --- .../mongodb/realm/realmkmmapp/SchemaTest.kt | 47 +++++++++++++++++++ source/sdk/kotlin/sync/background-sync.txt | 7 +-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/examples/kotlin/shared/src/commonTest/kotlin/com/mongodb/realm/realmkmmapp/SchemaTest.kt b/examples/kotlin/shared/src/commonTest/kotlin/com/mongodb/realm/realmkmmapp/SchemaTest.kt index 26fd176fc99..eff761b8c84 100644 --- a/examples/kotlin/shared/src/commonTest/kotlin/com/mongodb/realm/realmkmmapp/SchemaTest.kt +++ b/examples/kotlin/shared/src/commonTest/kotlin/com/mongodb/realm/realmkmmapp/SchemaTest.kt @@ -8,6 +8,9 @@ import io.realm.kotlin.ext.query import io.realm.kotlin.ext.realmListOf import io.realm.kotlin.ext.realmSetOf import io.realm.kotlin.internal.platform.runBlocking +import io.realm.kotlin.mongodb.App +import io.realm.kotlin.mongodb.Credentials +import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.query.RealmResults import io.realm.kotlin.types.* import io.realm.kotlin.types.annotations.Ignore @@ -309,5 +312,49 @@ class SchemaTest: RealmTest() { Realm.deleteRealm(config) } } + @Test + fun test() { + class ShoppingCart: EmbeddedRealmObject { + var _id : String ="" + var active: Boolean = false + var brand: String = "" + var created : RealmInstant = RealmInstant.from(0,0) + var updated : RealmInstant = RealmInstant.from(0,0) + var name : String = "" + //var positions : RealmList = realmListOf() + } + class Blegh: RealmObject { + @PrimaryKey + var _id: String = "" + var _class: String = "" + + var created: RealmInstant = RealmInstant.from(0,0) + var updated: RealmInstant = RealmInstant.from(0,0) + + var shoppingCart : RealmList = realmListOf() + } + + val app = App.create(FLEXIBLE_APP_ID) + // use constants for query names, so you can edit or remove them later + val NAME_QUERY = "First query" + print(NAME_QUERY) + runBlocking { + val user = app.login(Credentials.anonymous(reuseExisting = false)) + val config = SyncConfiguration.Builder(user, setOf(Blegh::class)) + .initialSubscriptions { realm -> + add( + //realm.query("_id.@type == 'string'"), + realm.query(""), + "All subscriptions" + ) + } + .build() + val realm = Realm.open(config) + print("Successfully opened realm: ${realm.configuration.name}") + realm.close() + } + } + + } // :replace-end: \ No newline at end of file diff --git a/source/sdk/kotlin/sync/background-sync.txt b/source/sdk/kotlin/sync/background-sync.txt index c965bfe3778..30535dec3d6 100644 --- a/source/sdk/kotlin/sync/background-sync.txt +++ b/source/sdk/kotlin/sync/background-sync.txt @@ -41,8 +41,9 @@ logic as a standalone connection to your backend. As a result, you'll need to: #. Get the Realm sync configuration for your app -#. Authenticate a user to open the realm. You can use a user's cached - credentials if the user recently used the app. +#. :ref:`Authenticate a user ` to open the realm. + You can use a user's cached credentials for a logged-in user whose + refresh token has not expired. #. Open the realm, then use `SyncSession.downloadAllServerChanges() <{+kotlin-sync-prefix+}io.realm.kotlin.mongodb.sync/-sync-session/download-all-server-changes.html>`__ and `SyncSession.uploadAllLocalChanges() <{+kotlin-sync-prefix+}io.realm.kotlin.mongodb.sync/-sync-session/upload-all-local-changes.html>`__ @@ -120,7 +121,7 @@ To create a worker that periodically performs background sync: - If the realm frequently updates throughout the day, consider setting a repeat interval of 1-3 hours. - If the realm only updates a small number of times each day, it's best to - set a higher repeat interval and only background sync once or twice a day. + set a less frequent repeat interval and only background sync once or twice a day. 3. Enqueue your worker with the Android OS. Assign it a unique identifier so that you can update the job in the future.