【问题标题】:Mongo is not definedMongo 没有定义
【发布时间】:2019-01-10 05:30:10
【问题描述】:

我正在发现 moteor.js,但我在基础知识方面遇到了困难。到目前为止,我只是按照教程进行操作,一切都很好,直到我进入 Collections 部分。我的应用程序正在运行,mongod 正在运行,但由于某种原因,应用程序在此行崩溃

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

if (Meteor.isClient) {
  Template.hello.greeting = function () {
    return "Welcome to hannibal.";
};

Template.hello.events({
'click input' : function () {
  if (typeof console !== 'undefined')
    console.log("You pressed the button");
}
});
}

if (Meteor.isServer) {
  Meteor.startup(function () {
 });
}

当我在 localhost:3000 打开页面时,我收到此消息

ReferenceError: Mongo is not defined
at app/hannibal.js:1:28

知道为什么要这样做吗?我认为这可能是因为我在 Windows 上使用了流星。

【问题讨论】:

  • 你能发布更多你的代码吗?你在关注什么教程?网址?
  • windows版本支持什么meteor版本? Mongo.Collection 有点新,在 0.9.1 之前你必须使用 Meteor.Collection。
  • 我正在关注本教程:meteor.com/try/3

标签: mongodb meteor


【解决方案1】:

在 >v0.9.1 中,如果您在自定义包中使用 Mongo,请检查 package.js 是否在 onUse 中包含 api.use('mongo', [client, server])。见this related question。

【讨论】:

    【解决方案2】:

    听起来您安装了旧版本的 Meteor。

    从命令行运行meteor update。

    【讨论】:

      【解决方案3】:

      对我有用的是直接从 Meteor 导入 Mongo:

      import { Mongo } from 'meteor/mongo'
      

      【讨论】:

        猜你喜欢
        • 2014-05-10
        • 2016-05-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-10
        • 2013-09-03
        • 1970-01-01
        相关资源
        最近更新 更多