0

For example, I have a record that I don't want to sync offline or preserve with persistence for future write. Is there a way to cancel this?

firebase.firestore().collection('test').doc('mydoc').set({value: 123});

NOTE: This is diferent from this question because I want to cancel a write, not cached data. Because I want persistent data, but not for a particular write.

For example, I send some data, have no internet for half an hour, with the page still open (on a desktop) I want to cancel the write to the server.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ElBarto
  • 387
  • 2
  • 12

2 Answers2

1

There currently is no way to cancel writes (that have not yet been synchronized to the server). It's a valid API request though, so I'd recommend you file a feature request.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Won't it be possible to manually set the value to `null` after a certain amount of time? – klaasman May 21 '18 at 20:39
  • if you set to null you still trigger the onCreate on the server and other clients, in that case you have to timeout and do other logic, totally possible, but not what the question is about – ElBarto Aug 15 '18 at 20:21
0

You can use transaction. If it is not successful you write the data in SQLite db for example and you could retry to send it after some time having the written information from your SQLite db.

nasko700
  • 73
  • 1
  • 7
  • Explain a bit more – Mathews Sunny Aug 14 '18 at 18:15
  • Link to transactions: https://firebase.google.com/docs/firestore/manage-data/transactions Use onFailure function callback to save your data in cache memory and with kind of a timer you can trigger a function that tries again after some time if you need it. Transactions will fail when the client is offline so using it you don't send the data if user is offline - exactly what you need. – nasko700 Aug 15 '18 at 13:21
  • transactions fail on offline, they are immediately cancelled. The question aims to be able to cancel the manually or after a period of time, not if there is no internet – ElBarto Aug 15 '18 at 20:18
  • There is no such option to cancel already written data, but you can try to remove it or to write it in some table where it will contain temporary data and to write it or delete it (this will be your canceling) it after half an hour. – nasko700 Aug 17 '18 at 15:10