Node.js Mongoosejs fills in a completed field

My document has a document with a document. I wanted to know how I can fill out an internal document. I tried this, but it does not fill out my complete document.

        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},
});
+3
source share
2 answers

This seems to be bug # 601, which is open on github. We'll have to wait for the fix in the next version if they get to it.

0
source

Mongoose does not support nested populations. Therefore, this part is not valid:.populate('owner.company')

There is a plugin for this: https://github.com/buunguyen/mongoose-deep-populate

0
source

All Articles