1

I want to store an array of arrays using Realm, but if I use type mixed it throws an error:

[Error: A mixed property cannot contain an array of values.]

This is my sample code:

export const ContentScheme = {
    name: 'content',
    primaryKey: 'elementId',
    properties: {
        elementId: 'string?',
        currentTimeInfo: 'mixed',
    }
}

Inserting Data:-

let data = {
    elementId: '60d19799c0023702d41c1110',
    currentTimeInfo:[["03.41", "03.29"], ["03.30", "05.14"], ["05.18", "00.00"]]
}
Rafael Tavares
  • 5,678
  • 4
  • 32
  • 48
  • Realm does not use arrays. Please refer to the [supported data types](https://docs.mongodb.com/realm/sdk/react-native/data-types/field-types/) documentation. Perhaps you mean a 'Collection' type (results list etc) but the question needs clarity on what you're trying to accomplish. Please update the question. – Jay Jan 23 '22 at 16:26

1 Answers1

1

For my approach, I will create another schema CurrentTimeSchema and store it as array in ContentSchema.

Here is the solution.

export const ContentScheme = {
    name: 'content',
    primaryKey: 'elementId',
    properties: {
        elementId: 'string?',
        currentTimeInfo: 'CurrentTime[]', <-- store CurrentTime in []
    }
}

export const CurrentTimeSchema = {
  name: 'CurrentTime',
  embedded: true, <-- avoid creating new object of CurrentTime
  properties: {
    time1: 'string?',  <-- rename these
    time2: 'string?',
  }
};
Teo
  • 876
  • 9
  • 22