我的猫鼬模式:
mongoose.Schema({
title: 'string',
items: [{
uid: 'string',
type: {type: 'string'},
title: 'string',
items: [{uid: 'string', type: {type: 'string'}, text: 'string'}]
}]
});
Run Code Online (Sandbox Code Playgroud)
如何告诉mongoose项目(和项目项目)不是文档,而只是嵌套对象?我既不需要_id属性也不需要任何文档的功能,但我想定义它们并使用模式进行限制.
是_id: false够吗?
没有自己的架构的嵌入式文档数组(如上所示)将始终具有_id字段.如果要禁止_id它们必须拥有自己的架构,则需要在其架构定义上设置{ _id: false } 选项.
mongoose.Schema({
title: 'string',
items: [mongoose.Schema({
uid: 'string',
type: {type: 'string'},
title: 'string',
items: [mongoose.Schema({
uid: 'string',
type: {type: 'string'},
text: 'string'
}, {_id: false})]
}, {_id: false})]
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
810 次 |
| 最近记录: |