Meteor模板帮助器mongo调用崩溃应用程序

时间:2015-09-01 15:03:49

标签: mongodb meteor

我有一个Meteor应用程序,由于我正在尝试更多地使用模板和模板助手而变得非常反应迟钝。我在MongoDB中基本上有两个大型集合,说collection1有1531589个文档,collection2有1517397个文档。对于每个集合,其中的文档都遵循单个模式,即collection1具有自己的模式,collection2具有自己的模式。两个模式只有几个属性(~5)。在我的Meteor代码中,我采用了以下方法

Col1 = new Mongo.Collection('collection1');
Col2 = new Mongo.Collection('collection2');

publications.js

Meteor.publish('collection1', function() {
    if (Roles.userIsInRole(this.userId, 'admin')) {
        return Col1.find({"ID": "12345"});
    } else {
        this.stop();
        return;
    }
});

Meteor.publish('collection2', function() {
    if (Roles.userIsInRole(this.userId, 'admin')) {
        return Col2.find({"ID": "12345"});
    } else {
        this.stop();
        return;
    }
});

subscriptions.js

Meteor.subscribe('collection1');
Meteor.subscribe('collection2');

然后我有模板应该通过模板助手显示每个集合的数据,所以实质上是

<template name="superInfo">
  {{#each latestInfo}}
    <p>{{latestInfo.prop1}}</p>
    <p>{{latestInfo.prop2}}</p>
  {{/each}}
</template>

使用模板助手

Template.superInfo.helpers({
    latestInfo: function() {
        return Col1.find({"ID": "12345"}, {
            sort: {Date: -1},
            limit: 1
        });
    }
});

我知道错误可能取决于我如何查询/发布/订阅,我读过this这样的帖子,但我仍然无法找到最有效的方法。另一个问题可能是我如何在本地配置Mongo?我确保ID字段的每个集合都有索引,但这没有帮助。每当我使用这些模板启动我的应用程序和浏览器到页面时,它就会变得完全没有响应。

我在模板助手中添加了一些console.logs并注意到它们被调用了很多,因此也可能是一个问题。关于如何最好地解决这些问题的任何建议都将非常感激。

0 个答案:

没有答案
相关问题