How do i access the nested field from a document in Mongodb

Here is the data:

{
	"_id" : "123",
	"createdAt" : ISODate("2018-01-19T18:06:03.060Z"),
	"services" : {
		"servicenamw" : {
			"id" : 8217234,
			"accessToken" : "22234354",
			"email" : "test@gmail.com",
			"username" : "test",
			"emails" : [
				{
					"email" : "test@gmail.com",
					"primary" : true,
					"verified" : true,
					"visibility" : "private"
				},
				{
					"email" : "random",
					"primary" : false,
					"verified" : true,
					"visibility" : null
				},
				{
					"email" : "blob",
					"primary" : false,
					"verified" : true,
					"visibility" : null
				}
			]
		},
		"resume" : {
			"loginTokens" : [
				{
					"when" : ISODate("2018-01-19T18:06:03.074Z"),
					"hashedToken" : "qwerty43234"
				}
			]
		}
	}
}

Here is the meteor code

<template name ="user">
	{{UserName}}
</template>

Template.user.helpers({
	 UserName() {

	 return Meteor.userId().services.servicename.username;
	 
	}
});

It does not return anything

Just taking a quick look, maybe it is a typo? You have “servicenamw” not “servicename”.

–jw

oh but that i changed it, sorry about that but its not a type issue

You are using Meteor.userId() when you should use Meteor.user()

Meteor.user().services.servicename.username;

1 Like

The issue is still not resolved, is there a problem with the template?

It only returns that data if you publication returns that data. So check your publication.

could you check what console.dir(Meteor.user()); is giving you?

Update : The issue is resolved!!!, I had some issues on the server(Meteor.publish()), thanks @chris74656, for the correction

1 Like

yeah!! my bad, thanks for your help