I have this publish file:
Meteor.publish('userSubscription', function() {
if(this.userId) {
return Meteor.users.find({_id: this.userId},
{fields: {'subscription': 1}})
}
})
and my react container file:
export default class SettingsWrapper extends TrackerReact(Component) {
constructor() {
super()
this.state = {
subscription: {
userSubscription: Meteor.subscribe('userSubscription')
}
}
}
componentWillUnmount() {
this.state.subscription.userSubscription.stop()
}
_user() {
return Meteor.user()
}
render() {
const subscription = this._user().subscription
console.log(subscription)
....
}
}
It’s supposed to grab subscription object in my users collection:
"subscription" : {
"plan" : "premium_monthly",
"payment" : {
"card" : {
"type" : "Visa",
"lastFour" : "4242"
},
"nextPaymentDue" : 1466231481
}
}
But I when I console.log(this._user().subscription.plan) it says ‘cannot read property plan of undefined’.
So I changed my publish file to this:
Meteor.publish('userSubscription', function() {
if(this.userId) {
return Meteor.users.find({_id: this.userId},
{fields: {'subscription.plan': 1,
'subscription.payment.card.type': 1,
'subscription.payment.card.lastFour': 1,
'subscription.payment.nextPaymentDue': 1}})
}
})
but it says same thing…
How do I grab some custom data from users collection?