2

I'm using realm for Javascript using React-native

I want to generate a realm schema to hold an array of Object as this:

arrayOfObj:[{ key1:1111, key2:2222, key3:333 }]

What I have tried so far is using the mixed type in my schema

const mySchema = {
    name: "mySchema",
    properties: {
        _id: "objectId",
        arrOfObj: "mixed" //'have used mixed[] too but they all don't work
    }
}

I have tried using mixed and also using mixed[] but when I try to insert the array of object i get the error: mySchema.arrOfObj must be of type 'mixed?[]', got 'object' ([object Object])].

Now, What is the correct data type for the array of object in realm?

Amani
  • 227
  • 1
  • 10
  • Mixed types seems to be still in beta https://github.com/realm/realm-js/releases/tag/v10.5.0-beta.1 – Michael Bahl Aug 05 '21 at 07:39
  • Do you wanna store any data in the array or do you know the structure of the data ? – Michael Bahl Aug 05 '21 at 07:40
  • @MichaelBahl I want to store **One object in an array with key-value pair of ObjectId: Integer**, something like this `[ {'60b6c1381d5d2f2afe4b3b' : 2, '51b6c15a1d7d6a2ba99a6c' : 3} ]` – Amani Aug 06 '21 at 05:12
  • @MichaelBahl can you provide some help please? – Amani Aug 09 '21 at 06:57

1 Answers1

1
const myScheme = {
  name: "myScheme",
  primaryKey: "_id",
  properties: {
   _id: "objectId",
   _partition: "string",
   name: "string",
   tasks: "myData[]"
 }
};

const myData = {
  name: "myData",
  primaryKey: "_id",
  properties: {
    _id: "objectId",
    _partition: "string",
    firstname: "string",
    lastname: "string",
 }

};

Michael Bahl
  • 2,941
  • 1
  • 13
  • 16