将 Meteor 与 MongoDB 一起使用

Using Meteor with MongoDB

我无法让我的非常简单的流星教程阅读我在 Mongodb 中的 collections 并打印到页面上。这是在流星网站上找到的官方教程。任何帮助将非常感激。如果有人想连接到工作区并进行更改,请告诉我,我可以授予访问权限。

这是我工作区的 link:https://ide.c9.io/hilldesigns/meteor

Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
  tasks: function () {
    return Tasks.find({});
   }
 });
}

这是 HTML 标记:

<head>
<title>Todo List</title>
</head>

<body>
  <div class="container">
 <header>
  <h1>Todo List</h1>
 </header>
   <ul>
   {{#each tasks}}
     {{> task}}
   {{/each}}
  </ul>
</div>
</body>

<template name="task">
    <li>{{text}}</li>
</template>

改变

Template.body.helpers({
  task: function () {
    return Tasks.find({});
   }
 });

Template.body.helpers({
  tasks: function () {
    return Tasks.find({});
   }
 });

只需在js文件中将"task"设为复数,这样returns一个数组,每个语句都可以运行通过。

mongo 数据库中有任何内容吗?

尝试向数据库添加一个任务,看看是否获得页面更新。

使用:

meteor mongo

db.tasks.insert({ text: "Hello world!", createdAt: new Date() });

不确定将助手附加到主体,1.2.1(最新版本)不支持它。如果您在浏览器中打开控制台,它应该会显示有关无法访问未定义的助手的错误。

所以,要让它发挥作用...

<head>
<title>Todo List</title>
</head>

<body>
  <div class="container">
 <header>
  <h1>Todo List</h1>
 </header>
   {{> todos}}
 </div>
</body>

<template name="todos">
  <ul>
  {{#each tasks}}
    {{> task}}
  {{/each}}
 </ul>
</template>

<template name="task">
    <li>{{text}}</li>
</template>

Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
// This code only runs on the client
Template.todos.helpers({
  tasks: function () {
    return Tasks.find({});
   }
 });
}

工作正常

这是我的流星列表

autopublish           1.0.4  (For prototyping only) Publish the entire database to all clients
blaze-html-templates  1.0.1  Compile HTML templates into reactive UI with Meteor Blaze
ecmascript            0.1.6* Compiler plugin that supports ES2015+ in all .js files
es5-shim              4.1.14  Shims and polyfills to improve ECMAScript 5 support
insecure              1.0.4  (For prototyping only) Allow all database writes from the client
jquery                1.11.4  Manipulate the DOM using CSS selectors
meteor-base           1.0.1  Packages that every Meteor app needs
mobile-experience     1.0.1  Packages for a great mobile user experience
mongo                 1.1.3  Adaptor for using MongoDB and Minimongo over DDP
session               1.1.1  Session variable
standard-minifiers    1.0.2  Standard minifiers used with Meteor apps by default.
tracker               1.0.9  Dependency tracker to allow reactive callbacks

meteor 是 1.2.1