I want to remove one value from an array in Firestore. I am using firebase functions and am updating this field after the deletion of a User. I have tried updating the array, I have tried arrayRemove, and a variety of other lines. Because I have to deploy every time I want to run a test it is getting time consuming and data is difficult to build and delete every time.
So I was hoping someone could help with this solution I found here:
I want to loop through a list of IDs (Users in the DB) and pull out their matches, and remove a specific ID from their list of matches.
When I run this, it doesn't know what firebase.firestore is. So I am not sure how to register firestore with this type of FieldValue.delete(). What is this section looking to target? "admin.FieldValue.delete()"?
admin.firestore()
.collection("Users")
.doc(matches[i])
.update({
[userId]: firebase.firestore.FieldValue.delete(),
});
I have also tried this:
admin
.firestore()
.collection("Users")
.doc(matches[i])
.update({
matches: admin.firebase.firestore.FieldValue.arrayRemove(userId),
});
but again it doesn't know what firebase.firestore is. What is the correct method to removing one value from an array?
Also, I am concerned about making a callout in a for loop but I am not seeing a way around it. Does anyone have any suggestions? These don't need to be async as all of the transactions are not reliant on one another.
error message i get in firebase functions:
ReferenceError: firebase is not defined