typescript - Firebase 函数中的 Firestore 查询始终为空
问题描述
我有一个 Firebase 函数,它获取数据并将其用于查询 Firestore。查询始终返回 null,即使数据库中有等效数据。
我已经尝试对 id 进行硬编码,但它仍然返回 null,所以我确定问题不在于查询中使用的数据。
查询:
/**
* Returns a user
* @param {string} userId the user id.
* @return {any} The user.
*/
async function getUser(userId: string): Promise<any> {
const userResponse =
await admin.firestore().collection("users")
.where("id", "==", userId)
.limit(1)
.get();
if (userResponse.docs.length > 0) {
return userResponse.docs[0];
} else {
return null;
}
}
它被称为:
/**
* Deletes the user account
*/
export const someFunction = functions.https.onCall(
async (data, context) => {
if (!context.auth) {
return {status: "error", code: 401, message: "Not signed in"};
}
try {
const firestore = admin.firestore();
const userId = data.userId.trim();
const userData = await getUser(userId);
functions.logger.info(
"User data: ",
userData
);
...
数据结构如下
已经坚持了很长一段时间了,所以非常需要任何帮助。提前致谢
解决方案
推荐阅读
- r - R数据框的值在错误的列中
- python - .gitlab-ci Django 中的 mysql 服务
- cplex - 如何从 CPLEX OPL 导出最佳后处理可行解决方案
- java - 在 android studio 中创建图像映射视图
- image - SSRS 表达式打开特定报告
- r - 如何提取出现最大值的矩阵的特定行和列
- nftables - nftables netdev 和 inet 钩子之间的区别
- python - Python:来自 csv-list 的值
- assembly - 在这个 MIPS 汇编程序中传递到标签是如何工作的?
- c# - Outlook for Office365 在发送前向用户显示消息