Set select: false to subdocuments array at mongoose Set select: false to subdocuments array at mongoose mongoose mongoose

Set select: false to subdocuments array at mongoose


Try creating a CommentSchema first,

var CommentSchema = new Schema({  user: ObjectId,  content: String  //whatever else});

and then in your PostSchema specify

comments: { type: [CommentSchema], select:false}


Well you could do this:

comments: { type: Array, default: [], select: false }

But you would be losing the declared structure underneath, otherwise what is really wrong with:

comments: [{    user: { type: ObjectId, select: false },    content: { type: String, select: false }    createdAt: { type: Date, select: false }}]

Which may seem a bit terse, but likely someone thought it was sensible.