且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除不存在的密钥时,Firebase数据库不会返回错误

更新时间:2023-01-15 16:56:31

当操作完成后,如果密钥不存在,则Firebase实时数据库认为删除操作成功.当前操作是否实际删除了密钥并不影响密钥成功与否,因此您所看到的是预期的行为.

The Firebase Realtime Database considers a delete operation successful when the key doesn't exist after the operation completes. Whether the current operation actually deleted the key is not a factor in its success, so what you're seeing is the intended behavior.

如果您要进行的操作仅在最初存在该密钥时才成功,然后又主动将其删除,则需要

If you want to have an operation that only succeeds when the key was present initially and you then actively removed it, you will need to use a transaction.

Cloud Firestore遵循对不存在的文档执行删除操作的相同逻辑,因此看来Cloud Storage在这里很奇怪.据我所知,没有记录在案的造成这种差异的原因.

Cloud Firestore follows the same logic for delete operations on non-existing documents, so it seems Cloud Storage is the odd one out here. There is no documented reason for this difference, as far as I know.