MongoDB Get Specific Field From Collection in Meteor

2016 05 04 No Comments

Hello, today I wanted to get one field from my collection in meteor.

For this, I created template helper and added two parameters like this.

Template.registerHelper( 'getInfo', (id, field) => {
    return Users.findOne({ _id: id}).[field] 
});

Now I am getting specific information of user by specific id.

Usage in template:

{{getInfo userID "user_name"}}

or you can use like this:

<img src="{{getInfo userID "user_avatar_url"}}" />

Enjoy 🙂