首页 > 解决方案 > 如何从 Firestore 中的查询返回结果?

问题描述

我正在尝试从查询中返回结果。我已经阅读了 100 个问题,但它们都只是向我展示了如何记录结果。我的查询似乎成功,但我的客户没有收到响应。

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();
        });
    }
}

谁能向我解释我做错了什么?

注意:在将其标记为重复之前,请注意,没有一个类似的问题涉及返回结果。

标签: node.jstypescriptfirebasegoogle-cloud-firestoregoogle-cloud-functions

解决方案


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


推荐阅读