如何删除Firebase中的大节点 [英] How to delete a large node in firebase

查看:46
本文介绍了如何删除Firebase中的大节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Firebase子节点,其中包含约1500万个子对象,其总大小约为8 GB数据.

I have a Firebase child node with about 15,000,000 child objects with a total size of about 8 GB of data.

示例数据结构:

firebase.com/childNode/$pushKey

each $pushKey contains a small flat dictionary: 
{a: 1.0, b: 2.0, c: 3.0}

我想尽可能高效和轻松地删除此数据.怎么样?

我尝试过的方法:我的第一次尝试是放置请求:

What i Tried: My first try was a put request:

PUT firebase.com/childNode.json?auth=FIRE_SECRET
data-raw: null

响应:{错误":请求的数据超出了单个请求可以访问的最大大小.请联系support@firebase.com寻求帮助."}

response: { "error": "Data requested exceeds the maximum size that can be accessed with a single request. Contact support@firebase.com for help." }

所以那行不通,让我们提出一个限制请求:

So that didn't work, let's do a limit request:

PUT firebase.com/childNode.json?auth=FIRE_SECRET&orderBy="$key"&limitToFirst=100
data-raw: null

响应:{错误":查询此请求类型不支持的相关参数"}

response: { "error": "Querying related parameters not supported on this request type" }

到目前为止,还没有运气:(写一个脚本,该脚本将获得第一个X个键,然后创建一个将每个值设置为null的补丁请求?

No luck so far :( What about writing a script that will get the first X number of keys and then create a patch request with each value set to null?

GET firebase.com/childNode.json?auth=FIRE_SECRET&shallow=true&orderBy="$key"&limitToLast=100

{错误":不支持混合"浅和查询参数"}

{ "error" : "Mixing 'shallow' and querying parameters is not supported" }

这真的不容易吗?我可以删除较浅的要求并获取密钥,然后完成脚本.我只是希望会有一种更简单/更有效的方式??

It's really not going to be easy this one? I could remove the shallow requirement and get the keys, and finish the script. I was just hoping there would be a easier/more efficient way???

我尝试的另一件事是创建一个侦听childAdded的节点脚本,然后直接尝试删除那些子级?

Another thing i tried were to create a node script that listen for childAdded and then directly tries to remove those children?

ref.authWithCustomToken(AUTH_TOKEN, function(error, authData) {
  if (error) {console.log("Login Failed!", error)}
  if (!error) {console.log("Login Succeeded!", authData)}

  ref.child("childNode").on("child_added", function(snap) {
    console.log(`found: ${snap.key()}`)
    ref.child("childNode").child(snap.key()).remove( function(err) {
      if (!err) {console.log(`deleted: ${snap.key()}`)}
    })
  })
})

该脚本实际上现在挂起,但是之前我确实收到过类似Firebase的最大堆栈限制警告之类的信息.我知道这不是firebase的问题,但是我看不出有什么特别简单的方法可以解决该问题.

This script actually hangs right now, but earlier I did receive somethings like a max stack limit warning from firebase. I know this is not a firebase problem, but I don't see any particular easy way to solve that problem.

推荐答案

下载浅树将仅下载密钥.因此,您可以下载所有密钥,而不用要求服务器订购和限制.

Downloading a shallow tree, will download only the keys. So instead of asking the server to order and limit, you can download all keys.

然后,您可以在客户端进行订购和限制,然后将删除请求批量发送到Firebase.

Then you can order and limit it client-side, and send delete requests to Firebase in batches.

您可以使用以下脚本作为灵感: https://gist.github.com/wilhuff/b78e7391396e09f6c614

You can use this script for inspiration: https://gist.github.com/wilhuff/b78e7391396e09f6c614

这篇关于如何删除Firebase中的大节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆