3

私の文書には文書がある文書があります。内部ドキュメントにもデータを入力する方法を知りたかったのです。これを試しましたが、内部ドキュメントにデータが入力されていません。

        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},
});
4

2 に答える 2

0

これは github で公開されているバグ #601 のようです。彼らがそれに到達した場合、次のバージョンでの修正を待つ必要があります.

于 2012-05-31T22:23:04.737 に答える
0

Mongoose はネストされた人口をサポートしていません。したがって、この部分は無効です。.populate('owner.company')

そのためのプラグインがあります: https://github.com/buunguyen/mongoose-deep-populate

于 2015-04-17T17:25:52.970 に答える