Local Realm data does not sync from client (Swift) to server via Device Sync.
Steps done:
I am new to Mongo I am trying to implement Atlas Device Sync for my application. Here are the steps I have followed
- Enabled Flexible Sync with Development mode ON , added queryable fields.
- Enabled anonymous authentication
- Schema was generated automatically as changes were done on client side.
Here is the object model
class VLocation: Object ,ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var accuracy: Double?
@Persisted var address: String?
@Persisted var timestamp: Date?
@Persisted var systemId: String?
@Persisted var eventType:String
@Persisted var deviceImei: String?
@Persisted var batteryLevel : Int?
@Persisted var isDataAvailable:Bool?
@Persisted var isMoving:Int?
@Persisted var cacheTimeStamp: Date?
}
- Added swift code for anonymous login to Realm with App ID
- Able to write to realm Vlocation using below syntax successfully
Let locationData = Vlocation()
…. //other data
location.eventType = “Location”
…//other data
try! realm.write {
realm.add(locationData)
}
- Added subscription to be able to upload on server
let configuration = user.flexibleSyncConfiguration(initialSubscriptions: { subs in
subs.append(QuerySubscription<VLocation> {
$0.eventType == "Location"
})
})
writeToLocation(realm, user)
Observation:
App Services shows below logs and everything seems fine but no document is inserted in VLocation.
Logs:
[
"Session closed after receiving UNBIND event",
"Session was active for: 0s"
]
Function Call Location:
US-VA
Query:
{
"VLocation": "(eventType == \"Location\")"
}
Session Metrics:
{
"downloads": 1
}
Logs:
[
"changing query from existing query to new query",
"Roles selected for sync:",
" readAndWriteAll: [ VLocation ]"
]
Function Call Location:
US-VA
Query:
{
"VLocation": "(eventType == \"Location\")"
}
Is there anything else that needs to be done to be able to successfully upload local realm documents to server?