Skip to content

What is the typeof of a QuerySnapshot?

With firebase, you can get documents in a collection like this: const collectionData = await collectionPath.get(); using collectionData, you can loop with:

collectionData.forEach(doc=>{ // doc here is a document, and we can get data with}); 

The above code makes collectionData behave like an array of documents. However, you can still treat it like an object by calling things like size? e.g collectionData.size will return the size of items in there.

My question is, what data type is a QuerySnapshot or the data returned by calling .get() on a firebase reference?


The QuerySnapshot is a regular JS object with a few custom methods in it, and one of them is the forEach method that essentially works as a proxy, kind of shortcut, to the actual docs.forEach array method.