node.js - Mongoose returns default value when excluded in find -


my user schema is,

{   _id: string,   name: string,   status: {type: string, "default": "notverified" } } 

in mongoose query, need exclude status field result.

my model query like,

user.find({}, {status: false}, function(err, users) {    // process error    if (err) console.error(err);     // process result    console.log(users); }); 

in above query, excluded status, in result documents default value defined in schema. i.e status: "notverified"

even though issue mongoose, quick fix, tried approaches mentioned here how exclude fields document.

but doesn't , work, because queries returns single document, toobject() work, want exclude array of documents, doesn't have toobject() method.

any other possible working solution(before marking duplicate)?

you misused mongoose's projection:

user.find({}, {status: 0}, function(err, users) {   // process error   if (err) console.error(err);   // process result   console.log(users); }); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -