[英]Firestore expressjs: how to get document where specific field exists and update the document
所以我在 firebase 云 function 中使用 expressjs 试图获取一个特定字段与我已经拥有的值相同的文档,所以这是一段代码:
const email =data.email (this is coming from stripe webhook )
const document = db
.collection('ConnectedAccounts')
.where(`email`, '==', email)
.get();
console.log('document', document.data());
获得此文档后,我想在其中存储一个新字段,我尝试了上面的代码但失败了,有人可以帮忙吗?
当您执行查询时,响应是一个可以包含任意数量文档的QuerySnapshot
。 因此,您需要遍历该快照中的文档以获取各个结果:
const email =data.email (this is coming from stripe webhook )
const querySnapshot = await db
.collection('ConnectedAccounts')
.where(`email`, '==', email)
.get();
querySnapshot.docs.forEach((docSnapshot) => {
docSnapshot.ref.update({ ... your update here ...});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.