Firebase CLI 删除与 Rest API 更新为 null
Firebase CLI delete vs Rest API update with null
此处的目标是尽快删除,使 Firebaes 实时数据库实例利用率保持在 100% 以下。
我在 Firebase 实时数据库中有 360 GB 的数据。现在我想删除大部分不需要的数据。我有使用 firebase database: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 database:remove /node1/child1 更新为 null。它会删除 child 1 的所有 child 吗?这两种方法之间的区别?
如果您将 null 值传递给 firebase 路径,那么它应该与删除该路径相同。
Passing null for the new value is equivalent to calling remove(); namely, all data at this location and all child locations will be deleted.
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);
}
您应该使用 firebase database:remove
,详见 this blog post。通过仅调用 remove()
或 update(null)
,您将锁定数据库直到所有数据被删除,对于如此大的数据集,这可能需要数分钟甚至数小时。
CLI 命令将分块和批量删除到合理的大小,防止您的数据库利用率被完全锁定。事实上,使用 database:remove
您不需要手动批处理——您只需将需要删除的最大节点传递给它,它就会自动为您处理批处理。
此处的目标是尽快删除,使 Firebaes 实时数据库实例利用率保持在 100% 以下。
我在 Firebase 实时数据库中有 360 GB 的数据。现在我想删除大部分不需要的数据。我有使用 firebase database: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 database:remove /node1/child1 更新为 null。它会删除 child 1 的所有 child 吗?这两种方法之间的区别?
如果您将 null 值传递给 firebase 路径,那么它应该与删除该路径相同。
Passing null for the new value is equivalent to calling remove(); namely, all data at this location and all child locations will be deleted.
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);
}
您应该使用 firebase database:remove
,详见 this blog post。通过仅调用 remove()
或 update(null)
,您将锁定数据库直到所有数据被删除,对于如此大的数据集,这可能需要数分钟甚至数小时。
CLI 命令将分块和批量删除到合理的大小,防止您的数据库利用率被完全锁定。事实上,使用 database:remove
您不需要手动批处理——您只需将需要删除的最大节点传递给它,它就会自动为您处理批处理。