How can I add a primary key and index to an object in studio


#1

Is it possible to alter a property in studio so it becomes a PK and will be indexed?
Otherwise is it possible to do that when creating a realm from CSV data?
If both is not possible, how can I achieve that with JavaScript? Could not find any documentation about this topic, at least not for JS.


#2

@386sx yes click add class and it should allow you to specify a primary key


#3

Thanks, I figured that but my question was not specific enough. The question was if this is possible with an existing realm with objects.
I created a new one from the JS client, but it would be still interesting if it’s possible to alter a schema (add indexes) in studio or with JS.


#4

@386sx No - you cannot change the primary key, this would be a destructive change

https://docs.realm.io/platform/using-synced-realms/migrating-your-data#destructive-changes


#5

Thanks, this is clear, how about adding an index?


#6

@386sx Sure you can add an index after the schema is instantiated - doesn’t seem like we can can do that from Studio - I will add this to our backlog

You can do this in JS here:


#7

@386sx See the discussion here:

Looks like indexes are per-client anyway