Reputation: 121
I'm using firestore in my react app. It is working without any problems when trying to get/create/update documents. However I am unable to access FieldValue which I need to update an array using arrayUnion. My firebase version used is 6.6.2.
Specifically this is the code I'm trying to get to work:
const locations = firebase.firestore.FieldValue.arrayUnion('location 1')
firebase.firestore().collection('config').doc('groups').update({ locations })
firebase.firestore()
is working in the exact same file but firebase.firestore.FieldValue
is undefined.
Upvotes: 2
Views: 3356
Reputation: 121
The solution was to import FieldValue directly from the firebase package and NOT from the instantiated firebase app.
import firebase from 'firebase/app'
const arrayToUpdate = firebase.firestore.FieldValue.arrayUnion(value)
Upvotes: 8
Reputation: 1274
It does seem like an issue with the way you're importing firebase.
My app is initialized as:
admin.initializeApp(functions.config().firestore);
I have an arrayUnion when using it like this:
import * as admin from 'firebase-admin';
const firestoreAdmin = admin;
const firestoreInstance = admin.firestore();
// Example: admin.firestore.FieldValue.arrayUnion('entry-to-add'),
Upvotes: 0
Reputation: 4465
I believe since you are setting your initializeApp
to app
, you will instead want to use app.firestore.FieldValue;
Upvotes: 1