Jeff Plummer
Jeff Plummer

Reputation: 73

Error deleting field from firestore from a web app. "Unsupported field value: a custom DeleteFieldValueImpl object"

Receiving error "ERROR FirebaseError: Function DocumentReference.update() called with invalid data. Unsupported field value: a custom DeleteFieldValueImpl object (found in field t1)" when trying to delete a document field in Firebase from a web application.

For testing purposes I've created a test collection/document "/test/ZJ6UMPjc7DEQdKKphTxJ" that is

{
  "t1": "test",
  "t2": "test2"
}

and ran code that should delete the "t1" field.

this.fStore.doc('/test/ZJ6UMPjc7DEQdKKphTxJ').update({
        "t1": firebase.firestore.FieldValue.delete()
      });

However, when I run the code in my angular app I get the above error. The error seems to be because the web sdk can't write objects. But all the documentation at "https://firebase.google.com/docs/firestore/manage-data/delete-data" says this is the correct way from a web app.

I've tried updating all the libraries, and still no go. My dependencies currently are

"@angular/fire": "5.2.1",
"firebase": "6.1.1",
"firebaseui": "4.0.0",
"firebaseui-angular": "3.4.2",

Any ideas?

Upvotes: 2

Views: 468

Answers (1)

Jeff Plummer
Jeff Plummer

Reputation: 73

I found the problem. I'll leave this here in case other people try to wrap all their firebase logic into a shared library.

In my application, both my frontend and my backend touch Firestore. To ease maintenance, I pulled all Firestore access into its own library that receives an instance of the firestore object from the app (frontend or backend). To say that simply, my front end or backend create and configure an instance of firestore, then pass that object to my shared library. Now I only have to edit firestore paths and logic in 1 place.

The problem arises with Delete and having my shared library import firebase and using an instance of firebase.firestore.FieldValue.delete(). The way firestore is written, my application can handle the FieldValue.delete() from my app. But will vomit if it receives the FieldValue.delete() imported from my shared library. Even if the versions are the same, Javascript "instanceOf()" says FieldValue from one shared library is different than the app instance.

Upvotes: 3

Related Questions