所以我有以下架构:
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]
}
}
)
但是,我不希望这个架构(子文档)不创建_id
字段。我该怎么做呢?我知道你可以改变原来的架构本身,但它正在被其他架构使用,我希望在其中填充_id
。
要在_id
上抑制item_detail_template
,您需要重新构建创建子文档的方式,如下所示
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);
如果你想仅在_id
模式中的item_detail_template
上抑制List
:
var List = new Schema(
{
item_details_template: {
_id:false, // should supress _id property
default: [
...
var widgetSchema = new Schema({ ... attributes ... }, { versionKey: false });