简体   繁体   English

流星未输出MongoDB查询

[英]Meteor not outputting MongoDB query

main.html: main.html:

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

main.js main.js

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

publications.js 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. 我一直试图获取main.html来显示数据库中的ID。 The user's ID can be in multiple documents in the "data" table, nested within data.potentialUsers.user_id. 用户ID可以位于“数据”表中的多个文档中,嵌套在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. 我不明白的是,当我将查询放入meteor mongo (在命令行中)时,查询成功执行。

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. 您仍然需要编写一个函数来将它们传递到html。

main.js 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: 然后在您的html中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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