Mongoose __v property - hide?
Solution 1:
You can disable the "__v" attribute in your Schema definitions by setting the versionKey
option to false
. For example:
var widgetSchema = new Schema({ ... attributes ... }, { versionKey: false });
I don't think you can globally disable them, but can only do it per Schema. You can read more about Schema's options here. You might also find the Schema set method helpful.
Solution 2:
To disable '__v' property, which is not recommended, use the versionKey
schema option:
var Schema = new Schema({...}, { versionKey: false });
To hide it from all queries, which sometimes can be not what you want too, use the select
schema type option:
var Schema = new Schema({ __v: { type: Number, select: false}})
Solution 3:
Two ways:
{versionKey: false}
when you query, like
model.findById(id).select('-__v')
'-'
means exclude the field