繁体   English   中英

firebase.firestore.FieldValue.arrayUnion 不是 function

[英]firebase.firestore.FieldValue.arrayUnion is not a function

我正在尝试更新我的 Firestore 中的数组,我遵循了 Google 提供的文档(https://firebase.google.com/docs/firestore/manage-data/add-data )但它不起作用,我还检查以确保我拥有最新版本的 firebase npm 模块。

这是我的代码:

> db
                    .collection('Data')
                    .doc('One')
                    .collection('Doc')
                    .doc(this.$route.params.id.toLowerCase())
                    .update({
                        myArr: firebase.firestore.FieldValue.arrayUnion(
                           'test'
                        ),
                    })
                    .then(() => console.log('Successfully written'))
                    .catch(err => console.log(err));

Firebase npm 模块已过时。 不得不手动重新安装

这已作为@google-cloud/firestore v0.16.0 的一部分发布。 它还不能通过 Firebase Admin 使用,但很快就会发布。 请注意,函数名称是admin.firestore.FieldValue.arrayUnion() ttps://github.com/firebase/firebase-admin-node/issues/323

"firebase-admin": "^6.0.0", 是添加arrayUnion的版本。 升级 npm 包。

检查https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/CHANGELOG.md#060

import firebase from 'firebase/app'

const arrayToUpdate = firebase.firestore.FieldValue.arrayUnion(value)

如果您使用 javascript 的新模块化版本 9,请使用以下代码

import { getFirestore, arrayUnion, updateDoc } from "firebase/firestore";
const db = getFirestore(config);    
const pathRef = doc(db, "doc", "id");
    await updateDoc(pathRef , {
        myArr: arrayUnion("test")
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM