2

I want to look into a child to look for another child. I want to find my current Uid in someone elses uid. How do I do that?

guard let currentUid = Auth.auth.currentUser?.uid else { return }
guard let (this is missing) = ... else { return } 

Database.database().reference().child("users-following").child(" ... ").child(currentUid)

The "this is missing" and child("...") indicate, where I am not getting anywhere. Can someone help me? I want to look in this child("…") to check and see if my currentUid is in that list.

______ UPDATE _______

"user-followers : {
  "YsBqvPlRGMfx..." : {
    "iFjaXB7lI..." : 1 
  }
},

iFjaXB... is the user, that deletes the account. All his data is being deleted as it's supposed to. But the id stays within the YsBq child in the "user-followers". So, I want to delete the child "iFjaXB" in the child of "YsBq". How do I do this?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
JuFa512
  • 119
  • 7
  • I'm not entirely sure I understand the question. Can you edit it to show the data at `users-following` (as text, no screenshots please)? You can get this by clicking the "Export JSON" link in the overflow menu (⠇) on your [Firebase Database console](https://console.firebase.google.com/project/_/database/data). – Frank van Puffelen Aug 05 '21 at 18:09
  • I want users to be able to delete their accounts. In my app they can follow each other. But when a user deletes their account, the users id does not get deleted in the user-following data. I managed to delete all their content and what so ever, but their uid stays within the "users-following". Database.database().reference().child("users-following").child(THIS IS THE ID I NEED).child(currentUid) And the currentUid is the one I want to delete, but I cannot do that without knowing what value to put in the child before the child(currentUid). HELP – JuFa512 Aug 05 '21 at 19:12
  • Can you edit it to show the data at users-following (as text, no screenshots please)? You can get this by clicking the "Export JSON" link in the overflow menu (⠇) on your [Firebase Database console](https://console.firebase.google.com/project/_/database/data), and you can add it to your question by clicking the `edit` link under it. – Frank van Puffelen Aug 05 '21 at 20:11
  • `"user-followers" : { "YsBqvPlRGMfx..." : { "iFjaXB7lIATw..." : 1 } },` iFjaXB... is the user, that deletes the account. All his data is being deleted as it's supposed to. But the id stays within the YsBq child in the "user-followers". So, I want to delete the child "iFjaXB" in the child of "YsBq". How do I do this? – JuFa512 Aug 05 '21 at 21:34
  • @FrankvanPuffelen I have updated my question to make it easier to read the exported JSON data.. – JuFa512 Aug 05 '21 at 21:38
  • I think I see the problem. Your current data structure makes it easy to find the followers for a given user, so to find `iFjaXB7lI...` when you know `YsBqvPlRGMfx...`. It does however not make it easy to find the followeds, given a follower (so the inverse). To allow that you'll need to set up an additional, inverted data structure, where you have `iFjaXB7lI...` as the first level, and then `YsBqvPlRGMfx...` under that. For more on this, see my answers here https://stackoverflow.com/q/40656589, https://stackoverflow.com/1/27207059 and https://stackoverflow.com/a/41528908. – Frank van Puffelen Aug 05 '21 at 22:44
  • I do also have the inverted, with "user-following". In there it goes like this: reference -> child(currentUid) -> child(uid). So in this case it would be: "user-following" -> iFjaXB.. -> YsBq.. The deletion works perfectly fine in that reference. But not in the "user-followers" reference .. – JuFa512 Aug 05 '21 at 22:54
  • also I have a function `func unfollow()`. In there I have `Database.database().reference().child("user-followers").child(uid).child(currentUid).removeValue()` and that works perfectly fine. I tried to implement the same code in the account deletion function but it didn't work .. – JuFa512 Aug 05 '21 at 22:58
  • We're missing a lot of context here it seems, and trying to add that interactively in comments is proving not very efficient. Please edit your question to show the [minimal-but-complete code snippet we can run to reproduce the problem](http://stackoverflow.com/help/mcve) and the minimal-but-complete JSON that the code reads and manipulates. – Frank van Puffelen Aug 05 '21 at 23:05

1 Answers1

1

I got things going. This is how:

Database.database().reference().child("here you put the one, that stores your currentUid".child(currentUid).observe(.childAdded) { (snapshot) in
let key = snapshot.key

Database.database().reference().child("user-followers).child(key).child(currentUid).removeValue()
JuFa512
  • 119
  • 7