1

I am getting undefined when trying to query a collection, please what is wrong? When I ran it on the console it returns the same thing. In the Mongodb record, everything exist. I posted the screenshot using Robomongo.

userDetails: function () {
        if (!Meteor.user()) {
            Bert.alert("You are not logged in, permission denied.", "danger", "growl-top-right");
            return false;
        }else{
            return UserDetailsList.findOne({userId: Meteor.userId});
        }
    }

This is the blaze template:

<p>{{userDetails.industry}}</p>
<p>{{userDetails.profession}}</p>

Robomongo screenshot to show record exists

UC Browser console

halfer
  • 19,824
  • 17
  • 99
  • 186
ken4ward
  • 2,246
  • 5
  • 49
  • 89
  • Hello, may be this post is helpful to you. Check it out https://stackoverflow.com/questions/28648980/meteor-mongo-findone-returns-undefined-in-method?noredirect=1&lq=1 – bpjoshi Jul 03 '17 at 08:02
  • 1
    Have you published / subscribed to the collection? – rubie Jul 03 '17 at 09:09
  • You also want to add `()` to `Meteor.userId` in your helper - as you have it in the console screenshot – rubie Jul 03 '17 at 09:15
  • Which version of Meteor are you using? – Ankur Soni Jul 03 '17 at 09:42
  • Are you able to provide the subscription/publication block for this template? or are you able to test it to see if it works with autopublish? – 416serg Jul 03 '17 at 13:07
  • Yes. I have published and and subscribed. @Ankur Soni, I'm using version 1.2.1. I have used the same code snippet on a project and it works, though the version is most recent 1.4.3. Could it be version issue because I experienced this when updating. with version 1.4.3, it not mandatory to map fields to their variable but in version 1.2.1 it's mandatory. – ken4ward Jul 03 '17 at 13:13
  • @kehinde have you added `()` to `Meteor.userId` yet? – rubie Jul 03 '17 at 14:11
  • Yes. I did added it. – ken4ward Jul 03 '17 at 14:35
  • Is your subscription `ready()` when you run `.findOne()`? – Michel Floyd Jul 04 '17 at 02:02
  • @ Michel Floyd, I think you've hit the nail on the head, how do I implement this? – ken4ward Jul 04 '17 at 07:25
  • 1
    @kehinde - It would help to also add code pertaining to pub/sub in your current question. – blueren Jul 04 '17 at 11:49
  • 1
    Thank you very much guys. You've really helped me. A mistake cost the man-hour seeking for a solution. It was because I copied and pasted code so I didn't edit it thoroughly, so what I published was not what I was querying. – ken4ward Jul 04 '17 at 18:49

0 Answers0