Hey everyone,
I have been working on a game in Unity and I have reached the point where I want to add MongoDB to it. I have made a good progress on integrating Mongo, but I encountered a problem that I have not been able to solve yet, so I decided to ask your help.
I am working with synced realm.
After defining App Service Schema for each of my collection, I started creating validation rules for the fields to constrain allowed data types and value ranges.
I have a couple of properties that are defined as int. For example:
scoreMultiplier: {
bsonType: 'int',
minimum: 0,
maximum: 15
}
what is represented in the generated realm object model as
[MapTo("scoreMultiplier")]
public int ScoreMultiplier { get; set; }
When I try to update scoreMultiplier through Realm .NET SDK like this:
realm.Write(() =>
{
currentPlayer.ScoreMultiplier = 20;
});
local realm gets updated successfully, however sync request results in the following error:
TranslatorCorrectiveErasure Error - Failed to apply changes to MongoDB. This has been resolved by removing the object from the mobile device.
In the log I can see the following:
[
“MongoDB error: "Document failed validation: {\"failingDocumentId\": {\"$oid\":\"6606ac9ad19d741bf48189ef\"},\"details\": {\"operatorName\": \"$jsonSchema\",\"schemaRulesNotSatisfied\": [{\"operatorName\": \"properties\",\"propertiesNotSatisfied\": [{\"propertyName\": \"scoreMultiplier\",\"details\": [{\"operatorName\": \"maximum\",\"specifiedAs\": {\"maximum\": {\"$numberInt\":\"15\"}},\"reason\": \"comparison failed\",\"consideredValue\": {\"$numberLong\":\"20\"}},{\"operatorName\": \"bsonType\",\"specifiedAs\": {\"bsonType\": \"int\"},\"reason\": \"type did not match\",\"consideredValue\": {\"$numberLong\":\"20\"},\"consideredType\": \"long\"}]}]}]}}"”,
“Table: "Player"”,
“Primary Key: {ObjectID("6606ac9ad19d741bf48189ef")}”
]
As you can see, document failed validation because the considered type and value are not int.
After a little research, I concluded that the error stems from the fact that the int32 type is not a native javascript type.
The only solution I found to fix the error is to change the type to a much more permissive Number type. This workaround is fine for me, but if you have an idea how I could make this work with int type, please let me know.
The bigger issue is that I am not able to restore the deleted object on the client side on demand.
This TranslatorCorrectiveErausre Error is not propogated to the client so I can not handle this and even if I dispose and delete the realm, the newly created realm wont match with the backend realm.
The only way I managed to restore the deleted object is initiating a client reset by terminating and re-enabling sync. But this is not a viable approach from my perspective.
So my question, is there any other method to restore a deleted object on the client side? Or is there any method to revert the client object to its last valid state instead of deletion in case of a validation failure?
Thanks for your help in advance!
Geri