Ad

How Do I Return The Results From A Query In Firestore?

I am trying to return the results from a query. I have read 100 questions, but they all just show me how to log the results. My query appears to be successful, but my client does not receive the response.

export const myFunction = functions.https.onCall((data, context) =>
{
    const collection = getMyCollection();
    let query = collection.orderBy('time', 'desc');
    return query.get().then((snapshot) =>
    {
        return snapshot.docs.map((doc) =>
        {
            console.log("This prints");
            return doc.data();
        });
    }
}

Can anyone explain to me what I am doing wrong?

Note: Before marking this as a duplicate, please notice that none of the similar questions talk about returning the results.

Ad

Answer

export const myFunction = functions.https.onCall((data, context) =>
{
    const collection = getMyCollection();
    let query = collection.orderBy('time', 'desc');
    return query.get().then((snapshot) =>
    {
        return snapshot.docs.map(doc => doc.data());
    }
}

https://www.reddit.com/r/Firebase/comments/75s7p2/get_all_documents_to_get_array_of_usable_data/do8x99f?utm_source=share&utm_medium=web2x

Ad
source: stackoverflow.com
Ad