I have a NodeJS application with Mongoose ODM.
I want to select three particular fields from a collection.
Example my collection is “Users” having fields ‘_id’,’username’,’email’,’usertype’,’password’…
I want to select only ‘username’,’email’&’usertype’ .
This was my code
var query = models.User.find({}).select('UserName', 'Email', 'UserType');
This was working fine with mongoose 2 version,I updated to Mongodb 2.2 and Mongoose 3.3.1.
Now I am getting error
500 TypeError: Invalid select() argument. Must be a string or object.
Can anyone please suggest a solution?
Since mongoose 3 select() parameter can be either:
-before fields that need to be excluded)So you should either use:
or