firebase realtime database reads json with missing data

Viewed 124

I encountered a really weird problem today. Basically I a populated a database with some values, but when I read that data I realized I had missing data. My JSON looks like the following:

JSON as seen from console

When I read the data, I realized I was missing the last entry. My code is as follows:

database.ref("brands/").once('value').then(function (snapshot) {
        if(snapshot.val()){
            console.log(snapshot.val());
          } else {
            console.log('node does not exist!');
          }
    });

The JSON i received from this code was correct for Test1 and Test2. However, I couldn't see the results for Yole.

JSON results from read

I noticed that there were some JSONs initially that worked out perfectly fine for me, where I could read all the data. I tried changing some parts of it and I managed to narrow down this weird behavior with the following JSONS. The only difference is the entry 1591785585_Yole (which failed) vs 1591785585_Test3 (which worked).

JSON that FAILED

{
  "brands" : {
    "Test1" : {
      "1591782657_Test1" : {
        "impressions" : 0,
        "likes" : 0,
        "viewed" : 0
      },
      "1591789095_Test1" : {
        "impressions" : 0,
        "likes" : 0,
        "viewed" : 0
      }
    },
    "Test2" : {
      "1591789158_Test2" : {
        "impressions" : 0,
        "likes" : 0,
        "viewed" : 0
      }
    },
    "Yole" : {
      "1591785585_Yole" : {
        "impressions" : 1,
        "likes" : 0,
        "viewed" : 0
      }
    }
  }
}

JSON that worked!

{
  "brands" : {
    "Test1" : {
      "1591782657_Test1" : {
        "impressions" : 0,
        "likes" : 0,
        "viewed" : 0
      },
      "1591789095_Test1" : {
        "impressions" : 0,
        "likes" : 0,
        "viewed" : 0
      }
    },
    "Test2" : {
      "1591789158_Test2" : {
        "impressions" : 0,
        "likes" : 0,
        "viewed" : 0
      }
    },
    "Yole" : {
      "1591785585_Test3" : {
        "impressions" : 1,
        "likes" : 0,
        "viewed" : 0
      }
    }
  }
}

Hoping that the above will be replicable for anyone who tries it.

I'm wondering whats the explanation for this weird behavior and how to go about solving this please. Thank you!

0 Answers
Related