新的Mongo.Collection()错误Cloud9

时间:2015-05-14 05:45:38

标签: javascript mongodb meteor cloud9-ide

所以我学习了Meteor框架,我使用的是Windows 7,并按照教程创建了Leaderboard应用程序。当我使用终端(在localhost:3000上运行)运行它时应用程序工作正常,但是当我尝试在Cloud9上运行完全相同的代码时,我收到此错误:

Your code is running at https://leaderboard-sanidhya-singh.c9.io.
Important: use process.env.PORT as the port and process.env.IP as the host       in your scripts!

debugger listening on port 15454

/home/ubuntu/workspace/leaderboard.js:1
xports, require, module, __filename, __dirname) { PlayersList = new Mongo.Coll
                                                                ^
ReferenceError: Mongo is not defined
    at Object.<anonymous> (/home/ubuntu/workspace/leaderboard.js:1:81)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain [as _onTimeout] (module.js:497:10)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

代码:

PlayersList = new Mongo.Collection('players');

if (Meteor.isClient) {

Meteor.subscribe('thePlayers', function(){
            return PlayersList.find({createdBy: this.userId});
});

Template.leaderboard.helpers({
    'testFunction': function() { return "Output of testFunction"; },

    'players': function() { return PlayersList.find({createdBy: Meteor.userId()}, {sort : {score: -1, name: 1}}); },

    'playerSelected' : function() {
        var player = PlayersList.findOne(Session.get('selectedPlayer'));
        return player && player.name;       
    },

    'numberOfPlayers': function() {
        return PlayersList.find({createdBy: Meteor.userId()}).fetch();
    },

    'selected': function() { 
        return Session.equals(Session.get('selectedPlayer'), this._id) ? "selected" : '';

    }
}); 

Template.leaderboard.events({
    'click .player': function(event) {
        Session.set('selectedPlayer', this._id);
    },

    'click .inc': function(event) {
        PlayersList.update(Session.get('selectedPlayer'), {$inc : {score: 1}});
    },

    'click .remove': function(event) {
        PlayersList.remove(Session.get('selectedPlayer'));
    },

    'click .dec': function(event) {
        PlayersList.update(Session.get('selectedPlayer'), {$inc : {score: -1}});
    },

    'submit .addPlayer': function(event) {
            if(PlayersList.find({ name: event.target.newPlayer.value }).count() == 0) {
                PlayersList.insert({
                    name: event.target.newPlayer.value,
                    score: 0,
                    createdBy: Meteor.userId()
                });
            }
            else 
                alert('Player already exists!');
            event.target.newPlayer.value = "";
            return false;
       }


   });
}

if(Meteor.isServer) {
    Meteor.publish('thePlayers', function(){
            return PlayersList.find()
    });
}

0 个答案:

没有答案