node.js - Mongoose select: false not working on location nested object -


i want location field of schema hidden default. added select: false property it, returned when selecting documents...

var userschema = new mongoose.schema({  cellphone: {   type: string,   required: true,   unique: true, },  location: {   'type': {     type: string,     required: true,     enum: ['point', 'linestring', 'polygon'],     default: 'point'    },    coordinates: [number],    select: false, <-- here    }, });  userschema.index({location: '2dsphere'}); 

when calling :

user.find({ }, function(err, result){ console.log(result[0]); });

the output :

 {       cellphone: '+33656565656',     location: { type: 'point', coordinates: [object] } <-- shouldn't  } 

edit : explanation (thanks @alexmac)

schematype select option must applied field options not type. in example you've defined complex type location , added select option type.

you should firstly create locationschema , after use schema type select: false:

var locationschema = new mongoose.schema({     'type': {         type: string,         required: true,         enum: ['point', 'linestring', 'polygon'],         default: 'point'        },        coordinates: [number]     } });  var userschema = new mongoose.schema({     location: {       type: locationschema,       select: false     } }); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -