Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
Realm Studio

Modify Schema in a Realm Studio

Realm Studio te proporciona herramientas para realizar cambios no disruptivos en tu esquema. Puedes:

  • Agregar clases al esquema

  • Add properties to classes

Importante

If you make changes to your schema in Realm Studio, you must migrate the realm file when you use it in your client app.

After you make schema changes, you can add values to the new properties and classes from within Realm Studio. You can also create new objects based on your new classes and properties. This gives you a graphical user interface (GUI) tool to experiment with changes to your schema until you get the object model you need.

Una vez completados los cambios, puedes exportar las definiciones de tus modelos desde Realm Studio. Esto te proporcionará nuevas definiciones de clase en el lenguaje que prefieras, que puedes incorporar a tu código.

You can also save an updated version of the realm file to use in your app. When you save a realm file with an updated schema, you must perform a migration to use it in your app.

Para agregar una nueva clase a tu esquema:

  • Pulsa el + botón junto al encabezado Classes en la esquina superior izquierda de la ventana de Realm Studio

  • Name your new class

  • Designate a primary key (Optional)

  • Press the Add class button

Ahora verás una nueva clase en la lista de clases que se muestra en la barra lateral izquierda.

To add properties to a class:

  • Select the class where you want to add properties in the left-hand sidebar

  • Press the + button under the Create {Class Name} button in the upper-right hand corner of the Realm Studio window

  • Name your new property

  • Selecciona un tipo para tu nueva propiedad en el selector desplegable

  • Click the checkboxes to select Make this a list of strings and Optional: Allow a null value if needed

  • Press the Add property button

You'll see your new property displayed alongside the other class properties.

If you already have objects in your class, you can add values for this property by clicking into the property's field for each value. If this is a new class with no objects, you can create new objects in the class.

Tip

After you've made changes to your schema, you can export your new schema as class definitions.

To export updated class definitions:

  • Vaya a File > Save model definitions y seleccione su idioma preferido. Los idiomas compatibles son: Swift, JavaScript, TypeScript, Java, Kotlin y C#.

  • Specify a name and destination for your new class definitions. Press the Save button.

Si tu directorio de destino todavía no existe, Realm Studio lo crea. Dentro, encontrarás un archivo que contiene una lista completa de clases y propiedades, incluidas nuevas incorporaciones.

This is a great tool to iterate on your schema. You can also export class definitions in multiple languages for cross-platform development.

After you make changes to your schema, you can add values to new properties and even create new objects. If you want to then use this updated realm file in your app, you can save the data. Before you can use it in your client app, though, you'll need to perform a migration.

Realm requires you to increment the version monotonically when you change the schema. If you try to open a realm with an updated object schema without migrating, your client will throw an error.

For instructions on how to complete this migration, consult your SDK's migration guide.

Volver

Modify a Realm File

En esta página