Search code examples
javascriptfirebasereact-nativefirebase-realtime-databaserealm

Realm - Value not convertible to a number


Hello community :) I implemented lots of good working functionality with firebase -> realm. Now i tried to edit a structure and I am running through the wildest error messages.

What is right for sure:

  • Firebase sends the data
  • Data is Converted (e.g. Firebase has "brands" as array -> is converted to a string for Realm Schema)
  • The error appears when firebase updates
  • Not every firebase content has all fields (e.g. Like you can see out of Realm Schema some fields are optional: true)

Fields where i maybe expect an issue:

  • Maybe its not possible to say that the ReferentList is optional (or i implemented it wrong): See Realm Schema const ReferentsList

What i tried

  • Debug before realm.create (Realm set) Result: Every data came in the right format
  • Checked all input values if they are int, string, ...

Hopefully someone can help me here because i got completely stuck with this issue and its necesarry to continue for my project. I want to know:

  • The solution why or what to do
  • A posibility to debug realm in a better way Thank you in advance for your time and help :)

Error message: Value not convertible to a number

Firebase datastructure

  • "begin" : "2017-05-15T15:50:00.000Z",
  • "description" : "abc",
  • "end" : "2017-05-15T16:15:00.000Z",
  • "id" : 6,
  • "language" : [ 1 ],
  • "location" : "L 1.02",
  • "member" : 20,
  • "referent" : [ 1, 3 ],
  • "register" : true,
  • "title" : "Sound of Silence",
  • "track" : 6,
  • "type" : 3,
  • "brands" : [ 1, 2, 3 ]

Realm Schema

const ReferentListSchema = {
    name: 'ReferentList',
    properties: {
        id: {
            type: 'int',
            optional: true
        }
    }
}

const LanguageListSchema = {
    name: 'LanguageList',
    properties: {
        id: 'int'
    }
}

const EventSchema = {
    name: 'Events',
    primaryKey: 'id',
    properties: {
        id: 'int',
        begin: {
            type: 'date',
            optional: true
        },
        end: {
            type: 'date',
            optional: true
        },
        title: 'string',
        description: 'string',
        register: 'bool',
        member: {
            type: 'int',
            optional: true
        },
        language: {
            type: 'list',
            objectType: 'LanguageList'
        },
        location: 'string',
        referent: {
            type: 'list',
            objectType: 'ReferentList'
        },
        type: 'int',
        track: {
            type: 'int',
            optional: true
        },
        img: {
            type: 'string',
            optional: true
        },
        brands:{
            type: 'string',
            optional: true
        }
    }
}

Realm set

set(obj) {
  realm.write(() => {
      if(obj.referent){
          obj.referent = obj.referent.map(function(id) {
              return {id};
          })
      }
      if (obj.language){
          obj.language = obj.language.map(function(id) {
              return {id};
          })
      }
      realm.create('Events', obj, true);
  });
}


Solution

  • Solved:! The issue got solved through wrong data at firebase. Some Date Objects hasent been set correct.

    How i got to the solution When i tried to debugg the code i made a try/catch block around:

    try{
      realm.create('Events', obj, true);
    }catch(error){
      console.log(obj);
      console.log(error);
    }

    Through this debug i found the right data wich was wrong. Before it just showed me all objects and afterwards the error.

    I wont close this question because of the chance to help someone with the same issues.-