2012-05-25 142 views
3

我的文档有一个包含文档的文档。我想知道如何填充内部文档。我试过这个,但它并没有填充我的innter文件。Node.js Mongoosejs填充填充的字段

 Document.find({}) 
     .populate('owner') 
     .populate('owner.company') 
     .run(function(err,docs){ 
     if(err){ 
      req.flash('error', 'An error has occured. Please contact administrators.') 
     } 
     console.log(docs); 
     res.render('dashboard/index', { title: 'Dashboard', menu: 'Dashboard', docs: docs}); 
    }); 

var mongoose = require("mongoose"), 
    Schema = mongoose.Schema, 
    ObjectId = Schema.ObjectId, 
    DocumentObjectId = mongoose.Types.ObjectId; 

var Document = new Schema({ 
    filepath: {type: String, required: true}, 
    createdBy: {type: String, required: true}, 
    created: {type: Date, default: Date.now}, 
    owner: {type: ObjectId, ref: 'owner'} 
}); 

var Owner = new Schema({ 
    fullname: {type: String, required: true}, 
    company: {type: ObjectId, ref: 'company'} 
}); 

var Company = new Schema({ 
    name: {type: String, required: true}, 
}); 

回答

0

看来这是一个在github上打开的bug#601。必须等待下一个版本的解决方案才能实现。