我的文档有一个文档,它有一个文档。我也想知道如何填充内部文档。我已经尝试过了,但它没有填充我的内部文档。
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},
});