nil*_*rtz 2 firebase reactjs google-cloud-firestore
我在我的反应应用程序中使用 firestore。尝试获取/创建/更新文档时,它没有任何问题。但是,我无法访问需要使用 arrayUnion 更新数组的 FieldValue。我使用的 firebase 版本是 6.6.2。
具体来说,这是我试图开始工作的代码:
const locations = firebase.firestore.FieldValue.arrayUnion('location 1')
firebase.firestore().collection('config').doc('groups').update({ locations })
Run Code Online (Sandbox Code Playgroud)
firebase.firestore()在完全相同的文件中工作但firebase.firestore.FieldValue未定义。
解决方案是直接从 firebase 包而不是从实例化的 firebase 应用程序中导入 FieldValue。
import firebase from 'firebase/app'
const arrayToUpdate = firebase.firestore.FieldValue.arrayUnion(value)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2081 次 |
| 最近记录: |