It Doesn't Work the Way It's Supposed Too

1 min read

A day or two ago I was working on a side project and ran into an odd solution to a very common problem. In fact the problem is so common, it's not a problem. Let's look at a standard Meteor.users() record...

2 "_id": "aAfSERPtP4AMBitB9",
3 "createdAt" "2015-08-04T19:08:21.304Z",
4 "services": {
5 "password": {
6 "bcrypt": "$2a$10$KbMT1PsoozuHlL7cThzeKOtBkhu8Wcl4zDYJUMkzK..plHmNpm0.G"
7 },
8 "resume": {
9 "loginTokens": []
10 }
11 },
12 "emails": [
13 {
14 "address": "",
15 "verified": false
16 }
17 ],
18 "profile": []

I was building an administrator dashboard and wanted to show a list of all users and their email addresses. Naturally I noticed that the emails property of the user record is an array of objects. Using a typical syntax to display this value I did this:

1{% raw %}
2 {{emails[0].address}}
3{% end raw %}

This should have worked because I'm calling the first object in the array by it's index however, it didn't work at all. After some toying around and finally giving up and asking on The Meteor Chef slack room I found out that you have to do this:

1{% raw %}
2 {{emails.[0].address}}
3{% endraw %}

This is saying that emails has a property that is an array with a blank name and that array has an address property. This makes no sense, at all to me, but it works so that is what matters.

Hope this helps some others if they are struggling to display a user's email.