1

Firebase child nodes are randomly deleted in random times

I have a firebase project with a lot of children per node (in the range of 100k+) and it uses real time database. The problem is, sometimes, completely randomly, few child items simply get removed.

For example, given the following database structure:

**Project** (root)
   users
      user1
      user2
      user3
      .
      .
      .
      user100000

one of the nodes among user1, user2... user100000 would just randomly get removed. This happens so randomly out of nowhere, I cannot reproduce it, and only affects less than 1% of the time, so out of more than 100k children, only 200ish would disappear in the span of 3 month. I went through every line of the code, but there is no function that removes a node. I only use updateChildValues, observe(.childAdded..., observeSingleEvent, and queryOrdered. There is no single method that starts with remove. Any ideas on why this is happening?

My first intuition is I am calling some write API like setValue or updateValue with Nil, but I am on Swift and that is not possible. I also looked at Firebase Web update() deletes all other child nodes, but this actually removes every child other than the one being added, which is definitely not happening to me. Has anyone also experienced this issue? Any help would be really appreciated. Thank you.

-----EDIT-----

Here are some example APIs that I use with write function. item variable is a dictionary defined by let.

let databaseRef = Database.database().reference()
newReferece = databaseRef.child("users").child(UID)    
newReferece.setValue(item)

Another one:

theAPI.REF?.updateChildValues(dict, withCompletionBlock: { (error, ref) in
                if error != nil {
                    onError(error!.localizedDescription)
                } else {
                    onSuccess()
                }
            })
Jay
  • 34,438
  • 18
  • 52
  • 81
  • Please edit the question to show the code that isn't working the way you expect. – Doug Stevenson Oct 12 '19 at 18:02
  • There is not an explicit code that I can show. I could post the whole API code, but it would be extremely long. I am trying to find a possible cause for this since this error happens rarely, but does happen. Thanks. – realstarspace Oct 12 '19 at 18:05
  • Without seeing code, there is no way to explain what's happening. It's very likely you're doing something wrong somewhere. – Doug Stevenson Oct 12 '19 at 18:10
  • Just added some code. Thanks. – realstarspace Oct 12 '19 at 18:11
  • Just wanted to make sure, any observing, query API are read only, right? – realstarspace Oct 12 '19 at 18:18
  • Rest assured that Firebase will not delete your nodes on its own. What's happening here is one of two things; you may have rules in place that are denying a write in the first place (not likely), you may be running into a persistence issue *or* your .updateChildValues is overwriting that node. More specifically, when you write data that's nil to a node, the node is removed. So that means at some point the data you're trying to write is nil. – Jay Oct 13 '19 at 13:12
  • And take a look and this [Q&A](https://stackoverflow.com/questions/57972133/firebase-child-query-coming-up-nil-after-deleting-a-key-then-adding-it-back/57979435#57979435) regarding persistence because the OP thought their data was nil, when in fact it was not being sync'd the server. – Jay Oct 13 '19 at 13:18

0 Answers0