MongooseJS填充refs数组中的refs数组

时间:2014-09-07 02:40:01

标签: javascript node.js mongoose mongoose-populate

我有一个猫鼬对象如下:

var BoxSchema = new Schema({
    name: String,
    OwnerId: String,
    items: [{type: Schema.Types.ObjectId, ref: 'Item'}],
    created: {type: Date, default: Date.now},
    updated: {type: Date, default: Date.now}
});
mongoose.model('Box', BoxSchema);

var ItemSchema = new Schema({
    name: String,
    OwnerId: String,
    settings: {
        tools: [{type: Schema.Types.ObjectId, ref: 'Tool'}]
    },
    created: {type: Date, default: Date.now},
    updated: {type: Date, default: Date.now}
});
mongoose.model('Item', ItemSchema);

var ToolSchema = new Schema({
    name: String,
    type: {type: String},
    uses: [{type: String}]
    created: {type: Date, default: Date.now},
    updated: {type: Date, default: Date.now}
});
mongoose.model('Tool', ToolSchema);

现在我做了类似的事情:

Box.find().populate('items settings.tools').exec(function(err, boxes){
    console.log(boxes);
});

我发现项目填充得很好,但每个项目中的settings.tools不是。我怎么能填充它?

0 个答案:

没有答案