2016-03-19 27 views
0
var ChildSchema = new Schema({ 
    createdAt : Date, 
    name : String 
}); 

var ParentSchema = new Schema({ 
    children : [ChildSchema] 
}); 

通過上述模式,我希望有一些方法parent.children,如parent.children.getLatest()將返回被添加到基於createdAt如何在mongoose.js子文檔數組中定義實例方法?

parent.children最新child我想我只能定義每個child實例方法通過ChildSchema.methods.getName = function ...

回答

0

在當前文檔中未提及爲子文檔定義實例或靜態方法。

但是,您可以爲文檔中的要素定義實例或靜態方法,在此例中爲ParentSchema

相關問題