【问题标题】:Is it possible to access the FieldValue with node js cloud functions?是否可以使用节点 js 云功能访问 FieldValue?
【发布时间】:2020-07-01 04:37:09
【问题描述】:

我正在尝试从我在 FireStore 中声明的地图中删除用户。但是如何获取字段值?我认为应该是这样的firestore.FieldValue.arrayRemove(user.uid) 只有firestore 没有FieldValue 对象。如何从他的用户地图中删除用户?

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

const firestore = admin.firestore();

export const onUserDeleted = functions.region('europe-west1').auth.user().onDelete(async user => {
    const groups = await firestore.collection('groups').where('users', 'array-contains', user.uid).get();
    const promises : Promise<FirebaseFirestore.WriteResult>[] = [];
    groups.forEach(snapshot => {
        promises.push(snapshot.ref.update({
            'users' : ,
        }));
    }); 
    return await Promise.all(promises);
});

【问题讨论】:

    标签: typescript google-cloud-firestore google-cloud-functions firebase-admin


    【解决方案1】:

    使用 Firebase Admin SDK 时,使用代码中显示的导入,您通过 admin.firestore.FieldValue 引用 FieldValue。

    【讨论】:

    • admin.firestore() 和 admin.firestore 有什么区别?
    • 您可以在源代码中看到 - 单击 VS Code 中的定义(如果您正在使用该定义)。前者是一个返回 Firestore 实例的函数。后者是一个命名空间。
    猜你喜欢
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 2021-06-15
    • 2018-06-25
    相关资源
    最近更新 更多