How to delete a specific child from a child in Firebase

前端 未结 1 660
夕颜
夕颜 2021-01-16 07:59

I have an application where a user can create lists.

The user can share a list with other users. I already manage to create the sharing part, the one I\'m having i

相关标签:
1条回答
  • 2021-01-16 08:30

    There is no way to do a server-side delete of multiple items based on a condition with the Firebase Database. You must first retrieve the items (or just their IDs) matching the condition and then delete those.

    However, you can delete the list itself and all references to it in one go by using a multi-path update.

    I'd also recommend keeping a list of all the UIDs you've shared a specific list with, so that you don't have to loop over all users. Keeping many-to-many relations in both directions is quite common in Firebase and other NoSQL databases.

    For more see:

    • the blog post introducing multi-path updates
    • the blog post describing client-side fan-out using multi-path updates
    • my answer on strategies for updating denormalized data
    • my answer on modeling many-to-many relationships
    0 讨论(0)
提交回复
热议问题