0

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: enter image description here

I want to grab the current_period_end data so I can put it out on screen. how would I do this?

2
  • If you have only activeSubscriptions then you can use activeSubscriptions.data().current_period_end to get that data. Commented Apr 11, 2021 at 15:59
  • @suppa98 unfortunately that didn't work. any other suggestions? Commented Apr 11, 2021 at 19:13

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.