'data() is not a function for querying firebase

I've been trying to figure out how to query a Firebase database for a while, but to no avail. Here's what I have right now:

async query(){
    const bar = firebase.firestore().collection('foo');
    const res = await bar.orderBy('gopher').limit(20).get();
}

res isn't the actual data, but rather some sort of internal object:

{
    o_: {
        J_ : {
             fromCache: false,
             ne: true,
             ...
        }
    },
    q_ : {
         ...
    }
}

For the data structure, I have a collection called foo, and multiple documents with unique ids - which each have a numerical field called gopher. I'm trying to sort by gopher and get 20 documents at the top, but res.data() is not a function and res.data is undefined.



Solution 1:[1]

It should be res.docs not res.data

res.docs contains array firestore document snapshot.

To print all the data

console.log(res.docs.map(snap=>snap.data()));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1