Firebase CLI删除vs Rest API更新为空



此处的目标是尽可能快地删除,使Firebaes实时数据库实例利用率保持在100%以下。

我在Firebase实时数据库中有360 GB的数据。现在我想删除大多数不需要的数据。我有一个使用firebase数据库进行删除的脚本:remove/node1/child1(https://firebase.googleblog.com/2019/03/large-deletes-in-realtime-database.html)

节点结构

"node1":{
"child1":{
"thousand of child's node here i want to delete"
}, 
"child2":{
"thousand of child's node here i want to delete"
},
"child3":{
"child3 is required can not delete this one "
}
}

我在想,如果我更新路径firebase数据库:remove/node1/child1为null。它会删除子项1的所有子项吗?这两种方法的区别是什么?

您应该使用firebase database:remove,如本文所述。只需调用remove()update(null),就可以锁定数据库,直到删除所有数据,对于这么大的数据集,这可能需要几分钟甚至几个小时。

相反,CLI命令会将大块和批删除操作调整为合理的大小,从而防止数据库利用率被完全锁定。事实上,使用database:remove,您不需要手动进行批处理——您只需将需要删除的最大节点传递给它,它就会自动为您进行批处理。

如果将null值传递给firebase路径,那么它应该与移除该路径相同。

为新值传递null相当于调用remove((;即该位置和所有子位置的所有数据都将被删除。

Firebase文档

firebase admin中remove方法的实现(适用于android(也使用此设置为null。

/**
* Set the value at this location to 'null'
*
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> removeValueAsync() {
return setValueAsync(null);
}

Java 中的Firebase源代码

最新更新