【问题标题】:meteor not subscribing to data流星不订阅数据
【发布时间】:2015-11-17 08:18:55
【问题描述】:

我在我的 Meteor 应用程序中做错了,但根本无法找出它是什么。我没有在 UI 中收到任何数据。这是代码。

lib/common.js

Data = new Meteor.Collection('data2');

'data2' 是我创建的一个集合,在 mongo shell 中响应良好

服务器/app.js

Meteor.publish("Data", function() {
        return Data.find({});
    });

客户端/app.js

Meteor.subscribe("Data");

客户端/helpers.js

Template.home.helpers({

    results: function(){
     return Data.find();

}
});

我什至尝试在 find() 中指定两列-field1, 2 无济于事。

客户端/home.html

<template name="home">
<table class="table table-striped tablesorter z-depth-5">
    <thead>
            <tr>
              <th width="15%">field1</th>
              <th width="15%">field2</th>
            </tr>
    </thead>
    <tbody>
            {{#each results}}
            <tr>
            <td>{{field1}}</td>
            <td>{{field2}}</td>          
            </tr>
            {{/each}}
    </tbody>
  </table>

检查结果 -

Data.find().fetch()
[]

【问题讨论】:

  • 只是为了笑,Meteor.publish('myData',...) 和 Meteor.subscribe('myData') 以排除多次使用名称 Data 的问题
  • 将 'Data' var 更改为 'myData' - 仍然没有骰子。
  • Meteor.Collection 现在是 Mongo.Collection,尽管这不是您的问题。当您说“检查结果”时,您的意思是您在 Web 控制台中运行了它?
  • 我看不出你所做的有什么明显的错误。尝试将 autopublish 包放回去,看看数据是否显示。然后,您可以将问题缩小到您的出版物或订阅。
  • @DavidWeldon - 是的 - 在网络控制台中。

标签: mongodb meteor


【解决方案1】:

已解决:

我犯的错误是我从系统上安装 mongodb 时创建的 c:\data\db 目录调用“本地”数据库。但是流星数据库不在那里,而是驻留在 /.meteor 中。更正后,它可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    相关资源
    最近更新 更多