javascript - 如何使用nodejs从云firestore中的单个查询中获取响应对象?
问题描述
我正在尝试在 cloud firestore 中查询并尝试提取文档 id,还有另一个值也称为 cc 我能够提取信息但使用 .forEach 但我想问是否有另一种方法可以做到这一点是我的询问
const recipient = await db
.collection("Active")
.where("office", "==", "d")
.where("template", "==", "dt")
.where("attachment.Name.value", "==", "xyz")
.get();
const id = [];
const cc = [];
recipient.forEach((doc) => {
id.push(doc.id);
cc.push(doc.data().cc);
// console.log(JSON.stringify(doc.data()));
});
解决方案
如果查询结果中只有一个文档,
const recipient = await db
.collection("Active")
.where("office", "==", "d")
.where("template", "==", "dt")
.where("attachment.Name.value", "==", "xyz")
.get();
const id = [];
const cc = [];
id.push(recipient.docs[0].id);
cc.push(recipient.docs[0].data().cc);
推荐阅读
- matlab - 从旧的变量列表创建新的变量列表:新名称和值(Matlab)
- c++ - c++ chrono 计时错误?
- ios - 如何在 SwiftUI 中更新 TextField 的值?
- r - 使用 R 对字符串中的一些模式进行编号
- python - 无法将 .pb 图形转换为 tflite
- spring - 有没有办法避免使用 Spring Batch 两次处理同一个文件?
- asp.net - Flutter 创建多个布局
- javascript - Javascript - 如何在一个功能中点击播放多种格式的多个文件,例如视频和音频
- c# - 在 wpf 中启动后停止情节提要
- r - 将 .xlsx 文件写入 S3 存储桶时出现问题