如何检查变量是否是firstore firebase函数中的文档或集合引用的实例? [英] How to check if variable is instance of document or collection reference in a firstore firebase function?

查看:36
本文介绍了如何检查变量是否是firstore firebase函数中的文档或集合引用的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将文档引用作为输入传递的Firebase函数中,如何检查该引用是用于文档还是集合?

In a Firebase function that is passed a document reference as input, how can I check if that reference is for a document or a collection?

例如:

if(data.ref instanceof FIRESTORE_COLLECTION_REFERENCE) {
  //do something...
} else if (data.ref instanceof FIRESTORE_DOCUMENT_REFERENCE) {
  //do something else...
}

如果这是一种允许的检查方法,那么对该数据类型的正确调用是什么?如果不允许,我该如何检查?

What is the correct call to that data type if this is an allowable means to check? If not allowed, how can I check this?

推荐答案

首先,请确保已正确安装Firebase.现在,为了使其正常工作,您应该使用以下两种导入方式:

First of all, make sure you have Firebase correctly installed. Now, in order to make it work, you should use the following two imports:

import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.CollectionReference;

此后,您可以使用以下代码行:

Right after that, you can use the following lines of code:

if(data.ref instanceof CollectionReference) {
    //do something...
} else if (data.ref instanceof DocumentReference) {
    //do something else...
}

这篇关于如何检查变量是否是firstore firebase函数中的文档或集合引用的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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