[英]How to get subcollection references in Firestore [Node JS]
基本上,我的数据结构如下...
根集合=“企业”
-Docs of "Businesses" = various restaurant names For every business doc, there is a deals subcollection For every deals subcollection, there are documents of deals
我需要做的是遍历每个企业拥有的每笔交易并检查条件,如果满足该条件则删除该交易,这与问题无关。 我遇到的问题是在NODE JS中获取子集合引用的子集合和文档。 以下是到目前为止的内容。
function delDeals()
{
businessesCopy.forEach(element)
{
var dealsRef = db.collection('businesses').doc(element);
dealsRef.getCollections().then(collections => {
collections.forEach(collection => {
var foodRef = db.collection('businesses').doc(element);
var query = citiesRef.where('capital', '==', true).get()
.then(snapshot => {
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
});
})
.catch(err => {
console.log('Error getting documents', err);
});
});
});
}
在这里,businesssCopy =一个数组,其中填充了对根businesss集合中所有业务文档的引用。
Dealsref
基本上创建了对我使用forEach
遍历的每个文档的引用。
在我做dealsRef.get()
之后,对于每个循环我都在挣扎,它获取了我循环通过的每个业务文档的子集合。 在该for循环内,我想做的是能够获取每个业务文档的所有子集合,然后能够遍历每个业务的每个交易子集合的每个文档(交易),并在满足条件时删除该交易文档一定条件 我不确定如何为每个企业获取交易子集合的那些交易文档的引用。
我认为您正在寻找:
dealsRef.getCollections().then(collections => {
collections.forEach(collection => {
collection.where('capital', '==', true).get().then({
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
});
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.