So I have the following schema:
var List = new Schema( { item_details_template: { default: [ { "title": "Name", "content": "", "hidden": false, "order": 0, "the_type": "text" }, { "title": "Price", "content": "", "hidden": false, "order": 1, "the_type": "text" }, { "title": "Company", "content": "", "hidden": false, "order": 2, "the_type": "text" } ], type: [Item_Detail] } } )
However, I don't want ONLY this schema (subdocument) to not create _id
fields. How do I do this? I know you can change the original schema itself, but it's being used by other Schemas, where I would like the _id
to be populated.
3 Answers
Answers 1
To suppress _id
on the item_detail_template
, you need to restructure the way you create subdocument as follows
var mongoose = require("mongoose"); var subSchema = mongoose.Schema({ //your subschema content },{ _id : false }); var schema = mongoose.Schema({ // schema content subSchemaCollection : [subSchema] // item_details_template }); var model = mongoose.model('tablename', schema);
Answers 2
If you want to suppress _id
on the item_detail_template
in the List
schema only:
var List = new Schema( { item_details_template: { _id:false, // should supress _id property default: [ ...
Answers 3
var widgetSchema = new Schema({ ... attributes ... }, { versionKey: false });
0 comments:
Post a Comment