Create collection name from string or property, not directly from a strongly types class

I need to be able to declare the collection name when creating the first object in that collection.

The restriction currently is that Realm automatically creats the collection based on class (ie: Person) when I would like to declare the collection name either by a string param or a property in the class, maybe using an attribute if possible. Something like this:

[MapTo(Mongodb.CollectionName)] public string Type {get;set;}

Of, using the dynamic api and pass in the name and object, ie:

var test = { Type: “Employee” Name: “John” }

_realm.Write(() => {
_realm.dynamicapi.create(test.Employee, test) })

This is frustrating because I can use dynamicapi to get collection without using a strong type but cannot create a collection without using a string type.

Any help would be greatly appreciated
Thanks

This is not something we support or plan to support. There’s an expectation of 1:1 correspondence between the Realm schema and the MongoDB schema. You can create the schema dynamically (docs), but even then, you would need to create a Realm type for each collection you need and can’t have objects of the same Realm type get synchronized to different MongoDB collections.

Can you ellaborate on what is your use case as this is not something we’ve encountered before?

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.