简体   繁体   中英

Meteor not outputting MongoDB query

main.html:

{{#each getRequests}}
    <li><a href="/req/{{_id}}">{{_id}}</a></li>
{{/each}}

main.js

if (Meteor.isClient) {
    Meteor.subscribe('getRequests',{fbID : Meteor.user().services.facebook.id});
}

publications.js

Meteor.publish('getRequests', function(args) {
    return data.find({"potentialUsers.user_id" : args.fbID});
});

I'm stuck trying to get the main.html to display the IDs from the database. The user's ID can be in multiple documents in the "data" table, nested within data.potentialUsers.user_id. What I don't understand is that when I put the query into meteor mongo (in the command line) it executes successfully.

I am fairly new to meteor myself, but reading through the docs I see these issues.

Subscribe makes the documents available to the client from the publication. You still need to write a function to deliver them to the html.

main.js

if (Meteor.isClient) {
    Meteor.subscribe('getRequests',{fbID : Meteor.user().services.facebook.id});

    Template.body.helpers({
        getRequests: function(){
           return data.find() // since you want everything the publication has.
        }
    })

}

Then in your html:

{{#each getRequests}}
    <li><a href="/req/{{_id}}">{{_id}}</a></li>
{{/each}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM