I am using this same code in App.cs and LoginViewModel becuase I need the data from MongoDB in both of these classes before deciding the next Page for Navigation.
The Models are:
public class Player: RealmObject
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId Id { get; set; } = ObjectId.GenerateNewId();
[MapTo("owner_id")]
public string OwnerId { get; set; }
[MapTo("fullName")]
public string FullName { get; set; }
[MapTo("eMail")]
public string Email { get; set; }
[MapTo("country")]
public string Country { get; set; }
[MapTo("mobileNumber")]
public string MobileNumber { get; set; }
[MapTo("province")]
public string Province { get; set; }
[MapTo("city")]
public string City { get; set; }
[MapTo("profileImage")]
public byte[] ProfileImage { get; set; }
[MapTo("ageGroup")]
public AgeGroup AgeGroup { get; set; }
[MapTo("favouriteGames")]
public IList<Game> FavouriteGames { get; }
}
public class Game : RealmObject
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId Id { get; set; } = ObjectId.GenerateNewId();
[MapTo("name")]
public string Name { get; set; }
}
public class AgeGroup: RealmObject
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId Id { get; set; } = ObjectId.GenerateNewId();
public string AgeGroupName { get; set; }
}
Please not that the Game and AgeGroup are capped collections with just 5 to 6 documents which is read only and client does not write to these collections. My questions are:
What correction in this code will enable data download
Why the GetInstanceAsync does not return exception
GetInstanceAsync takes a cancellation token argument - you can use that to set a timeout (see this article for examples).
Regarding why GetInstanceAsync doesn’t throw an exception - it’s due to this bug - the original design of the API was assuming that eventually a connection will be established, so it’ll keep retrying the connection forever. We are now aware of certain conditions which will prevent sync from ever working (such as a schema mismatch), but haven’t gotten around to updating the API to communicate those errors.
Finally, I’m not sure why your code doesn’t work, but I’m guessing there’s an issue with the communication between the client and the server. This should be surfaced at least in the client logs, but also possibly in the server logs. Can you run your app and share the client logs from an attempted connection?
Sync is Enabled after generating schemas for the AgeGroup and Game Table from the Sample data. The original error still exists. You asked for the client logs. But I am not logging in the app. Can you please explain what info you want . The server logs sometimes show:
InitialSyncNotCompleted Error
Error:
attempted to start a session while initial sync is in progress (ProtocolErrorCode=229)
The Realm SDK will automatically log operations to the console. You can configure that to also log to a file if you’re not able to capture the console logs. Here’s the docs about it and the file logger would be something like:
Logger.Default = Logger.File("/usr/realm.log");
Make sure to call this before you create an App instance though.
The error you’re getting - Client tried to connect using flexible sync before initial sync is complete indicates that the server is still initializing sync. Generally that shouldn’t take a whole lot of time and only happens the first time you enable sync. If it doesn’t go away after a while, it likely indicates some issue with the server and/or your cluster (e.g. maybe you have a whole lot of data on a very small cluster).
You could check the server logs for any errors that could provide more insight into why initial sync is taking so long. If there’s nothing useful there, your best bet would be to open a support ticket and someone from the server team will investigate further.