I have this function:
firestore.collection('customers').doc(userID).collection('subscriptions')
.where('status', 'in', ['trialing', 'active']).get()
.then(activeSubscriptions => {
// if this is true, the user has no active subscription.
if (activeSubscriptions.empty === true) {
console.log("line 31")
{signOut(props.history)}
subStatus = "inactive"
}
});
Basically, in firestore, I have a customers collection, a doc with the user id, and then the subscriptions collection in which is created upon a user processing stripe. In the subscriptions collection, it has a doc which is the subscription id, and I have some fields I want to grab. See the attached picture:
I want to grab the current_period_end
data so I can put it out on screen. how would I do this?
If you are looking to access fields from a firestore document, you can do it by specifying the field in square brackets.
With a firestore structure like /customer/cus123/subscriptions/sub123
I was able to obtain a timestamp field of sub123
with this code:
let cusRef = db.collection('customer').doc('cus123').collection('subscriptions').doc('sub123');
cusRef.get()
.then(doc => {
if (!doc.exists) {
console.log('No such document!');
}
else
{
console.log('Name: ',doc.data()['name']);
console.log('Tmsp: ',doc.data()['tmsp123']);
}
});
I hope you find this useful.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.