I'm using device sync and am setting the initial subscription with a query that should only populate the local realm with items from a specific tenant. Strangely this works for some collections but not for others.
For instance my initial subscription is:
.initialSubscriptions { realm ->
add(
realm.query<item>("tenant == $0", tenantId),
"items"
)
add(
realm.query<department>("tenant == $0", tenantId),
"departments"
)
This works for my items, however I have in my realm departments where tenant != tenantId.
Is there other setup or index’s that need to be created for this to work? What am I missing here?
Hey Zach,
Here’s my old checklist for these things, you need to use common sense and just change collection name and whatever id thing you’re doing.
Troubleshooting Checklist for Device Sync Post-setup Part 3
-
Schema Definitions
- Field Names: Confirm that the
dog'
field name in the building
schema exactly matches the field name used in the query (dog == $0
).
- Field Types: Verify that the ‘dog’ field in the
building
schema is of the same data type as dogId
(e.g., both should be strings).
-
Data Integrity and Population
- Data Population: Ensure that the
building' collection contains data where the
dog’ field is correctly populated.
- Existing Data: Check that the departments expected to be filtered are stored with the correct
dogId
.
-
Field Indexing
- Indexing: Verify if the
tdog
field in the `building’ schema is indexed to improve query performance and accuracy.
-
Query Syntax and Logic
- Query Construction: Ensure the query syntax (
dog == $0
) is correct and accurately reflects the filtering condition.
- Dynamic Values: Confirm that
dogId
is correctly passed and not null or incorrectly referenced during subscription creation.
-
Initial Subscription Behavior
- Fresh Subscription: Ensure the initial subscription is applied freshly and not modifying an existing subscription without clearing it first.
- Testing with New Data: Test the subscription with a new dog and fresh data to isolate the issue.
-
Realm Sync Rules and Permissions
- Sync Rules: Verify that there are no sync rules or permissions interfering with the synchronization of `building documents.
- RBAC Permissions: Check that the user or role has the correct permissions for the
dog
collection.
-
Debugging and Logging
- Enable Logging: Enable detailed logging for Realm Sync to check for any errors or warnings related to the
building
collection.
- Inspect in Realm Studio: Use Realm Studio to inspect the local realm after the subscription is applied and verify that the data is populated as expected.
-
Schema Consistency and Synchronization
- Schema Consistency: Ensure that schema definitions in your client code and server are consistent and up-to-date.
- Resync Data: Consider resyncing data to ensure consistency after any schema changes.