Hi there,
Perhaps someone can help me, I am trying to set up custom user data but keep running into problems and I’m not sure the documentation is that clear. I am using the .NET SDK.
I have a series of RealmObjects which form my normal user data (such as Book, Person etc…). They are using a property _id as their primary key and a partition key of ownerId which is the user’s ID, all as suggested in the documentation, working very nicely.
Then following the documentation further I am adding a CustomUserData class. This is not a subclass of RealmObject. This class has a property _id which is the user’s ID and identifies it as belonging to that user. There is no ownerId property.
This is how I have sync set up in Realm:
And this is how I have Custom User Data set up:
As far as I can tell I have set everything up correctly as per the documentation. I get an error in the app when trying to access the data: Unknown: no rule exists for namespace UserData.CustomUserData
. OK fair enough, so on Realm, in Data Access=>Rules I find the newly added CustomUserData and select the ‘Users can only read and write their own data’ template’. This required a ‘Field Name For User ID’. This is where I get a bit confused, it’s not really in the docs how this should be configured for custom user data. Is this then the _id property? After I have done this I get a schema error:
OK so I can go back to the app now, and custom user data works. I can then generate the schema in Realm and it looks like this:
{
"title": "CustomUserDatum",
"properties": {
"Company": {
"bsonType": "string"
},
"FirstName": {
"bsonType": "string"
},
"LastName": {
"bsonType": "string"
},
"_id": {
"bsonType": "string"
}
}
}
So far so good. When I try to save the schema it’s not possible as I get the error schema for namespace (UserData.CustomUserData) must include partition key "ownerId"
. Oh dear. I can add it to keep it quiet but then I get the error: schema for namespace (UserData.CustomUserData) must have consistent types of partition key "ownerId" (expected: string, required: true; actual: string, required: false)
. If I would make it required I would need that property in the class too and… basically I am going around in a lot of circles and not sure exactly what I am supposed to be doing.
Could anyone tell me where I am going wrong here? I would suggest the documentation could be a little clearer too for people who aren’t the brightest such as me
Many thanks!!
Will