我的 firebase 集合设置如下:
customers
uid
subscriptions
subscriptions uid
items
plan: true or false
我需要访问这个计划变量来检查计划是活动的还是非活动的???如有必要,我可以在 firestore 中附上配置的照片吗?但这是我目前用于从 firestore 获取数据的代码。我还能继续使用它,但要相应地改变它吗?
firestore
.collection("profiledata")
.doc(userID)
.get()
.then((doc) => {
setProfileData(doc.data());
});
在第二张照片中——计划部分有一个“行”,表示活动或非活动......我需要抓住那个!
要获取用户的所有订阅(包含项目),它应该是:
firebase.collection('customers').doc(userID).collection('subscriptions').get()
.then(subscriptions => {
subscriptions.forEach(subscription => {
// subscription.data() should give you a subscription with its items
console.log(subscription.data());
});
})
如果订阅存在,这将是您查询具有status
'active'
给定客户的订阅的方式:
firebase.collection('customers').doc(userID).collection('subscriptions')
.where('status', '==', 'active').get()
.then(activeSubscriptions => {
// if this is true, the user has no active subscription.
console.log(activeSubscriptions.empty)
});
获取status
订阅:
firebase.collection('customers').doc(userID).collection('subscriptions').get()
.then(subscriptions => {
if (subscriptions.empty) {
console.log('User has no subscriptions')
} else if (subscriptions.size > 1) {
console.log('ERROR: User has multiple subscriptions')
} else {
subscriptions.forEach(theSubscription => {
// there is only this subscription
const data = theSubscription.data();
console.log(data.status);
});
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句