我希望我的模式中的位置
字段默认情况下应该是隐藏的。
我已经添加了select: false
属性,但是在选择文档时它总是被返回...
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'});
当调用:
User.find({ }, function(err, result){
console.log(result[0]);
});
输出结果为:
{
cellphone: '+33656565656',
location: { type: 'Point', coordinates: [Object] } <-- Shouldn't
}
编辑:说明(感谢@alexmac)
SchemaType选择选项必须应用于字段选项而不是类型。在您的示例中,您定义了一个复杂类型Location并向类型添加了选择选项。