Reputation: 969
In the Firebase documentation in the following link in the section Existing Data vs. New Data it states that the following rule is applied on the creation or deletion of data.
// we can write as long as old data or new data does not exist
// in other words, if this is a delete or a create, but not an update
".write": "!data.exists() || !newData.exists()"
Could someone explain me why the write permits the delete operation as this seems to me wrong?
In the same section of the documentation it states that: newData represents the merged result of the new data being written and existing data.
The problem is that if there is a delete operation then the data will exist and the newData will also exist as it is the merged result as the documentation states. As such, the expression !data.exists() || !newData.exists()
should return false.
Could someone please tell me if I am missing something?
Upvotes: 1
Views: 97
Reputation: 66355
It's saying:
Being able to delete data like that is convenient, especially when making an atomic update. Which means "do these multiple operations, but only if they all succeed". e.g.
dbRef.update({
history: { someNewKey: 'The transaction happened!' },
pending: { somePendingKey: null }
});
There we write an entry into the history table and delete the item from the pending table in one go by using an empty write.
Upvotes: 1