2

我正在尝试创建一个列表来显示teams我的数据库中的所有内容。我得到错误TypeError: Invalid select() argument. Must be a string or object.任何人都可以帮我弄清楚如何解决这个问题吗?我只是想用它来打印当前团队的列表,然后可以单击此团队列表来编辑团队名称!

所以在我Schema的 forTeam我有这个:

Team.statics.getAllMeta = function(cb){
  var query = this.find({}, ['key', 'name'], cb);
  return query.exec(cb);
};

然后在我的index.js routes我有这个:

var getAllMeta = function(req, res, next){
  Team.getAllMeta(function(err, teamsList){
    if(!err && teamsList){
      req.teamsList = teamsList;
    }
    next(err);
  });
};

这样我就可以像这样调用routes我的team页面:

  app.get('/team', getAllMeta, function(req, res){
    util.log('Serving request for url[GET] ' + req.route.path);
    res.render('team', {'teamsList' : req.teamsList});
  });

仅供参考,这里是来自的其他相关index.js部分routes

  app.get('/', function(req, res){
    logger.log('Serving request for url [GET]' + req.route.path)
    Team.getAll(function(err, allTeams){
      if(!err && allTeams){
        res.render('index', {'allTeams' : allTeams});
      }else{
        util.log('Error fetching team from database : ' + err);
        res.render('error');
      }
    });
  });

  app.get('/show/team/:key', function(req,res){
    Team.findByKey(req.params.key, function(err, teamData){
      if(!err && teamData){
        teamData = teamData[0];
          res.json({
            'retStatus' : 'success',
            'teamData' : teamData
          });
      } else {
        util.log('Error in fetchin Team by key: ' + req.params.key);
        res.json({
          'retStatus' : 'failure',
          'msg' : 'Error in fetching Team by key: ' + req.params.key
        });
      }
    });
  });
4

1 回答 1

1

尝试

var query = this.find({}, 'key name', cb);

https://github.com/LearnBoost/mongoose/issues/1087

于 2012-12-24T01:58:53.043 回答