mongoose.js 3:如何判断嵌套不是文档 [英] mongoose.js 3: how to tell that nested is not a document
本文介绍了mongoose.js 3:如何判断嵌套不是文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的猫鼬模式:
mongoose.Schema({
title: 'string',
items: [{
uid: 'string',
type: {type: 'string'},
title: 'string',
items: [{uid: 'string', type: {type: 'string'}, text: 'string'}]
}]
});
如何告诉猫鼬项目(和项目项目)不是文档,而是嵌套的对象?我既不需要_id
属性,也不需要任何文档的功能,但是我想定义它们并使用架构进行限制.
How to tell mongoose that items (and items of items) are not documents, but just nested objects? I need neither the _id
property nor any document's functionality for them, but I want to define them and restrict with schema.
_id: false
是否足够?
推荐答案
没有它们自己的架构的嵌入式文档数组(如上所示)将始终具有_id
字段.如果要禁止显示_id
,则它们必须具有自己的架构,并且需要设置{ _id: false }
Embedded document arrays without their own schema (like you show above) will always have an _id
field. If you want to suppress the _id
they have to have their own schema and you need to set the { _id: false }
option on their schema definition.
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})]
});
这篇关于mongoose.js 3:如何判断嵌套不是文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文