node.js - 如何从 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();
});
}
}
谁能向我解释我做错了什么?
注意:在将其标记为重复之前,请注意,没有一个类似的问题涉及返回结果。
解决方案
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());
}
}