We are using the react-native-firebase in one of our applications in which we have more than one reference (reference_A, reference_B, reference_C) at the same level and we want to restrict one of those references (reference_C) from getting synced with the Firebase Real-time Database but not the others.
For this, as suggested at Firebase Documentation and RNFirebase Documentation, we have used the 'keepSynced' method as below:
import database from '@react-native-firebase/database';
..
..
..
database().ref('/reference_C').keepSynced(false);
Also, to persist the data for offline usage, we have used the 'setPersistenceEnabled' as below:
database().setPersistenceEnabled(true);
But, when observed at the Firebase console, the 'reference_C' is getting synced when the device is coming online which is not as expected.
Any help with this is highly appreciated.
Thanks in advance.
keepSynced
doesn't work the way you expect. It's not possible to completely stop synchronization of a particular node. You use keepSynced
to indicate that you always want to synchronize a specific node. It's effectively the same as adding an empty listener to a node, so that changed in the database are synchronized with the client.
If you're seeing that reference_C
is getting synchronized, that means you added a listener to it somewhere else in your code, or you have a listener at the root node of the database, which is effectively synchronizing everything all of the time.