【发布时间】:2016-06-02 00:21:54
【问题描述】:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ChildSchema = new Schema({
name: String
});
ChildSchema.methods.getName = function () {
return this.name;
}
var ParentSchema = new Schema({
children: {
type: [ChildSchema]
default: []
}
});
ParentSchema.methods.getChildName = function () {
// How to facilitate ability to access instance of ChildSchema to call child.getName
}
var Parent = mongoose.model('Parent', ParentSchema);
在上面的代码中,我希望在ParentSchema 中访问ChildSchema 的getName 方法。在mongoose中怎么做?
非常感谢。
【问题讨论】: