0

I'm relatively new to firebase and need to delete a certain field from all records in Firestore. This is how the database record structure looks like

-> Profiles
  -> UUID ( md5 )
   -> consents ( This needs to be deleted for all profiles ) 

But not all of the profiles have these, and it's a huge database with around 150k records. I didn't do Firebase Functions so am not sure how to do this safely thanks in advance for any suggestions.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
saxonsxexe
  • 97
  • 5
  • The Firebase Realtime Database and Cloud Firestore are two separate databases. Please edit your question to only have the tag for the database you actually use, not with both. – Frank van Puffelen Feb 22 '23 at 14:19

1 Answers1

1

There is no operation to do a bulk update documents in Firestore and add a field to them, so you will have to update each document in turn.

So in a step-by-step process:

  1. Read a batch of documents from the database with a limit query.
  2. Loop over the documents in the result.
  3. Add the new field to each of them.
  4. Get the next back of documents by starting after the last one of the previous batch.

You might also want to read:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807