2012-09-27 15 views
1

我的貓鼬架構:mongoose.js 3:如何告訴嵌套不是文檔

mongoose.Schema({ 
     title: 'string', 
     items: [{ 
      uid: 'string', 
      type: {type: 'string'}, 
      title: 'string', 
      items: [{uid: 'string', type: {type: 'string'}, text: 'string'}] 
     }] 
    }); 

如何告訴貓鼬是(項目及項目)項目是不是文件,但只是嵌套的對象嗎?我既不需要_id屬性,也不需要任何文檔的功能,但我想定義它們並使用模式進行限制。

_id: false夠了嗎?

回答

6

嵌入式文檔數組沒有自己的模式(就像上面顯示的那樣)將始終有一個_id字段。如果您想取消_id,則必須擁有自己的架構,並且您需要在其架構定義上設置{ _id: false }option

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})] 
}); 
+0

好的,謝謝你的回覆! – WHITECOLOR