feaure/bug
When using sub documents in the schema and calling toJSON
- it seems there is no way to remove _id
fields from it.
Example
const ArticleSchema = new Schema({
title: {
type: String,
default: 'New article',
trim: true
},
slug: String,
types: [{
name: String,
slug: String
}]
}, { id: false });
// convert mongoose document to JSON
const types = req.article.toJSON().types;
res.json(types); // types will have name, slug and _id fields
node.js 6.10.10, mongoose 4.11.3, MongoDB 2.6.10
types: [new Schema({
name: String,
slug: String
}, { _id: false, id: false })]
Most helpful comment