germainelol
germainelol

Reputation: 3331

Node.js - Invalid select() argument

I am trying to create a list to show all the teams in my database. And I get the error TypeError: Invalid select() argument. Must be a string or object. Can anyone help me figure out how to solve this? I just want to use it to print a list of current teams, this list of teams can then be clicked on to edit the team name basically!

So in my Schema for Team I have this:

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

And then in my index.js routes I have this:

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

So that I can then call in the routes my team page like this:

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

Just for reference here are the other relevant parts in index.js from 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
        });
      }
    });
  });

Upvotes: 2

Views: 2894

Answers (1)

Amir T
Amir T

Reputation: 2758

Try

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

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

Upvotes: 1

Related Questions