Reputation: 26142
I have mongoose Shcema:
Track = new Schema({ title: 'string', artist: 'string' })
in my DB collection I've got object: { title: 'title1', artist: 'artist1', status: '1' }
Status is not in schema but it is still retrieved by find methods. I thought that schema should be able to restrict this.
Is it possible to retrieve this object by findOne ore findById etc without status attribute being automatically excluded without need to explicitly point it out by {status: 0}?
Upvotes: 0
Views: 342
Reputation: 311865
You can do this by adding the status
field to the schema but setting its selection default to false
:
Track = new Schema({
title: 'string',
artist: 'string',
status: { type: String, select: false }
});
Upvotes: 3