[英]Firestore expressjs: how to get document where specific field exists and update the document
So I am using expressjs in the firebase cloud function trying to get a document where a specific field is the same as a value that I already have, So here is the piece of code:所以我在 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());
after getting this document I want to store a new field to it, I have tried the above code but failed, can anyone help?获得此文档后,我想在其中存储一个新字段,我尝试了上面的代码但失败了,有人可以帮忙吗?
When you execute a query the response is a QuerySnapshot
that can contain any number of documents.当您执行查询时,响应是一个可以包含任意数量文档的
QuerySnapshot
。 So you need to loop over the documents in that snapshot to get at the individual results:因此,您需要遍历该快照中的文档以获取各个结果:
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.