0

I need to keep my firebase database synchronized so i ve made a little search and i found out that i can use keepsynced(true) because by default, Firebase keeps 10mb data in cache and if it grows further it will replace by new data so i ve used it like so ( working with firebase on a node app on glitch)

 var locationRef = admin
    .database()
    .ref()
    .child("locations");
 locationRef.keepSynced(true);
 locationRef.once('value').then(function(snapshot) {
        snapshot.forEach(function(childSnapshot) {
        var childKey = childSnapshot.key;
        var childData = childSnapshot.val();
          console.log(childData);
          presseLocations.push(childData)
                });

but i'm getting this error :

 locationRef.keepSynced is not a function

Any idea ?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Az Emna
  • 527
  • 2
  • 10
  • 26

1 Answers1

1

to keep your data synchronized you should use on() instead of once() because using once() gets the value from the database once, while using on() continues to listen for changes to the data until you call off()

Az Emna
  • 527
  • 2
  • 10
  • 26
  • 1
    That is indeed correct. Disk persistence/`keepSynced` don't work well with `once()`. See my explanation on why that is here: https://stackoverflow.com/questions/34486417/firebase-offline-capabilities-and-addlistenerforsinglevalueevent/34487195#34487195 – Frank van Puffelen Mar 07 '19 at 14:43