0
votes

I work on a bare react-native project where i have to use firebase persistence. I use react-native-firebase package to do all my request.

When i write offline with react-native-firebase/firestore and then go online, it sync with backOffice.

firestore().collection(col).add(data)

When i update data with react-native-firebase/firestore and then go online, it sync with backOffice.

firestore().collection(col).doc(id).update(data)

But when i write offline and then update this new data (offline), when i go online data disapear like the pending request are not sync.

Any idea why ?

thanks

1
in firestore when you update the same documents many times, only the last update get sync with the database. So what I guess here is that you updated your documents with some empty data in one last update and that one is the one that was synced to the database. does the document exist with empty data or it's not there at all?Methkal Khalawi
Yes the document exist thanks! The problem was that à field with the serverTimestamp() value was set to null when return online (logic)Hugo Bricoult

1 Answers

1
votes

serverTimestamp is quite complex topic in relation to firestore but the main point is that serverTimestamp value is never set on the client side and it's always null however it will be set only on the server. you can get this value by:

firebase.firestore.FieldValue.serverTimestamp()

your code to set it should be somthing like:

const firestore = firebase.firestore()
const ref = firestore.collection('messages').doc('foo')
ref.set({
    createdAt: firebase.firestore.FieldValue.serverTimestamp()
})

to have a deeper understanding on this, check out this detailed article by a firebase expert