Q:

How to check if variable is instance of document or collection reference in a firstore firebase function?

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?
Ex:
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?

A:

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...
}

