Meteor uncaught type error cannot read property

I have these 3 methods:

	getGroupId(){
		return UserResolutionGroups.findOne({active: true})._id;
	}

	resolutionGroups(){
		return UserResolutionGroups.find({}, {sort: {createdOn: -1}}).fetch();
	}

	resolutions(){
		return UserResolutions.find({groupId: this.getGroupId()}, {sort: {complete: 1, createdOn: -1}}).fetch();
	}

I know getGroupId works because the resolutionGroups() function returns all the groups and displays it on the UI.
However the resolutions function will only work with:

return UserResolutions.find({}, {sort: {complete: 1, createdOn: -1}}).fetch();

and not with:

return UserResolutions.find({groupId: this.getGroupId()}, {sort: {complete: 1, createdOn: -1}}).fetch();

Could someone please help with this.
I have tried moving the function order around incase it was to do with the function needing to be higher up in the order but I can unsure of this as the resolutionGroups() function is lower in order and works fine.

Thanks

A better design is keep Meteor methods disjoint from each other and handle params passing via the client. In theory, you could probably do something like Meteor.call('getGroupId') within a different method, but I don’t think this is a good practice. Using a remote method to call a function whose domain and range are in the same environment seems like syntactic overkill. Why not just use a regular function?

If you’re going to be publishing/calling for the groupId and the resolutions at the same time, why not just handle them in the same method/publication?

1 Like