Answer the question
In order to leave comments, you need to log in
How to hide _id and __v in mongoose?
Good afternoon!
How to hide _id and __v fields by default in Mongoose schema. (i.e. not just throw them out during transformation, but just make them select: false
).
Tried like this:
const UserSchema = new Schema({
_id: {
type: mongoose.Schema.ObjectId,
select: false
},
__v: {
type: Number,
select: false
}
});
.select('+_id')
Answer the question
In order to leave comments, you need to log in
No way :(
I just have each user has his own role, the roles contain which fields not to show.
You can make a separate static method that removes unnecessary keys from the object, but in any case, you have to put a crutch
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question