【问题标题】:Firebase CLI delete vs Rest API update with nullFirebase CLI delete vs Rest API update with null
【发布时间】:2020-03-07 04:22:45
【问题描述】:

这里的目标是尽可能快地删除,保持 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 database:remove /node1/child1 更新为 null。它会删除孩子 1 的所有孩子吗?这两种方法之间的区别是什么?

【问题讨论】:

    标签: firebase firebase-realtime-database firebase-cli


    【解决方案1】:

    您应该使用firebase database:remove,详见this blog post。只需调用 remove()update(null),您将锁定数据库,直到所有数据都被删除,对于这么大的数据集,这可能需要几分钟甚至几小时。

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

    【讨论】:

      【解决方案2】:

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

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

      Firebase documentation

      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 source code in Java

      【讨论】:

        猜你喜欢
        • 2011-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-14
        • 1970-01-01
        • 2021-10-14
        • 2012-07-28
        • 1970-01-01
        相关资源
        最近更新 更多