我在我的react应用程序中使用firestore。当尝试获取/创建/更新文档时,它可以正常工作。但是,我无法访问使用arrayUnion更新数组所需的FieldValue。我使用的firebase版本是6.6.2。
具体来说,这是我想要开始工作的代码:
const locations = firebase.firestore.FieldValue.arrayUnion('location 1')
firebase.firestore().collection('config').doc('groups').update({ locations })
firebase.firestore()
在完全相同的文件中工作,但firebase.firestore.FieldValue
未定义。
发布于 2019-10-18 17:08:44
解决方案是直接从firebase包导入FieldValue,而不是从实例化的firebase应用程序导入。
import firebase from 'firebase/app'
const arrayToUpdate = firebase.firestore.FieldValue.arrayUnion(value)
发布于 2019-10-01 23:49:20
我相信既然您将initializeApp
设置为app
,那么您将转而使用app.firestore.FieldValue;
发布于 2019-10-01 23:37:18
这似乎是你导入firebase的方式的一个问题。
我的应用程序初始化为:
admin.initializeApp(functions.config().firestore);
当我这样使用时,我有一个arrayUnion:
import * as admin from 'firebase-admin';
const firestoreAdmin = admin;
const firestoreInstance = admin.firestore();
// Example: admin.firestore.FieldValue.arrayUnion('entry-to-add'),
https://stackoverflow.com/questions/58186235
复制相似问题