错误:无实体可更新:应用程序-Firestore Cloud功能 [英] Error: no entity to update: app - Firestore Cloud Function

查看:45
本文介绍了错误:无实体可更新:应用程序-Firestore Cloud功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我非常基本的Cloud Function:

This is my very basic Cloud Function:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const db = admin.firestore()

exports.createdNewAccount = functions.auth.user().onCreate(event => {
    return db.collection('users').doc(event.data.uid).update({
        "creationDate" : Date.now()
    })
})

我得到了错误

错误:没有要更新的实体:应用

Error: no entity to update: app

我的代码有什么问题?

推荐答案

event.data.uid的文档很可能不存在. update()的文档指出:

Most likely, the document for event.data.uid does not exist. The documentation for update() states:

如果将更新应用于不存在的文档,更新将失败.

The update will fail if applied to a document that does not exist.

改为使用 set().

这篇关于错误:无实体可更新:应用程序-Firestore Cloud功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆