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 doc.data()});
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?
Advertisement
Answer
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.