I'm trying to delete a field in a Firebase document from a React app using firebase.firestore.FieldValue.delete()
but it isn't working. Reading and writing data to documents and collections is working fine but I am struggling to get FieldValue
to work. I've set up the Firebase instance in src/firebase.js
like this:
import app from 'firebase/app';
import 'firebase/firestore';
var config = {
******
};
class Firebase {
constructor() {
app.initializeApp(config);
this.fv = app.firestore.FieldValue;
this.db = app.firestore();
};
};
export default Firebase;
And then in the module that I am trying to use FieldValue
in I am doing:
import Firebase from "./firebase.js";
class App extends Component {
constructor(props) {
super(props);
this.firebase = new Firebase();
this.db = this.firebase.db;
this.fv = this.firebase.fv;
};
deleteFunction(id) {
this.db.collection("collection_id").doc("doc_id").update({
field_id: this.fv.delete()
});
}
};
However no variation of imports or doc references as mentioned here have been successful for me. I don't receive any errors and I know that the firestore instance is working correctly because I am using it to set and read the same data. I have also verified that the field_id
I am trying to delete is the correct id and that this.fv
is FieldValue
by console logging them both.
What am I missing? I feel like this should be super easy and straight forward and that I am overlooking something super obvious,