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
Post a Comment