在Firestore中删除包含所有子集合和嵌套子集合的文档

编程入门 行业动态 更新时间:2024-10-09 09:12:17
本文介绍了在Firestore中删除包含所有子集合和嵌套子集合的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何删除包含所有文档集合和嵌套子文档集合的文档? (在函数环境中)

How can you delete a Document with all it's collections and nested subcollections? (inside the functions environment)

在RTDB中,您可以ref.child('../someNode).setValue(null)并完成所需的行为.

In the RTDB you can ref.child('../someNode).setValue(null) and that completes the desired behavior.

我可以想到两种方法来实现所需的删除行为,这两种方法都具有严重的弊端.

I can think of two ways you could achieve the desired delete behavior, both with tremendously ghastly drawbacks.

  • 创建一个超级"功能,该功能将抓取每个文档并将其批量删除. 此功能可能很复杂,难以更改,并且可能需要很长的执行时间.

  • Create a 'Super' function that will spider every document and delete them in a batch. This function would be complicated, brittle to changes, and might take a lengthy execution time.

    为每种Document类型添加"onDelete"触发器,并使其删除任何直接子集合.您将在根文档上调用delete,并且删除调用将沿树"传播.由于功能执行的巨大负担,它速度慢,伸缩性差且成本高.

    Add 'onDelete' triggers for each Document type, and make it delete any direct subcollections. You'll call delete on the root document, and the deletion calls will propagate down the 'tree'. This is sluggish, scales atrociously and is costly due to the colossal load of function executions.

    想象一下,您将必须删除组"及其所有子级.对于#1来说将是非常混乱,而对于#2来说将是昂贵的(每个文档1个函数调用)

    Imagine you would have to delete a 'GROUP' and all it's children. It would be deeply chaotic with #1 and pricey with #2 (1 function call per doc)

    groups > GROUP > projects > PROJECT > files > FILE > assets > ASSET > urls > URL > members > MEMBER > questions > QUESTION > answers > ANSWER > replies > REPLY > comments > COMMENT > resources > RESOURCE > submissions > SUBMISSION > requests > REQUEST

    是否有一种高级/优惠/清洁的方式来删除文档及其嵌套的子集合?

    Is there a superior/favored/cleaner way to delete a document and all it's nested subcollections?

    考虑到您可以从控制台进行操作,应该有可能.

    It ought to be possible considering you can do it from the console.

    推荐答案

    根据firebase文档: firebase.google/docs/firestore/solutions/delete-collections 使用服务器端的node-JS可以轻松且整洁地删除带有嵌套子集合的集合.

    according to firebase documentation: firebase.google/docs/firestore/solutions/delete-collections Deleting collection with nested subcollections might be done easy and neat with node-JS on the server side.

    const client = require('firebase-tools'); await client.firestore .delete(collectionPath, { project: process.env.GCLOUD_PROJECT, recursive: true, yes: true });
  • 更多推荐

    在Firestore中删除包含所有子集合和嵌套子集合的文档

    本文发布于:2023-11-30 07:47:35,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1649232.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:嵌套   文档   Firestore

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!