Mongoose populate()返回没有错误的空数组

我一直在试图让这种填充的东西工作,但我得到的问题,因为我没有得到预期的结果,并没有错误的工作。 只是一个空arrays。

我的模型看起来像这样。 每个自己的文件

var mongoose = require('mongoose');

var upgradeSchema = new mongoose.Schema({ type: { type: String, default: "Any" }, ability: String, ability_desc: String, level: Number, tag: String }); mongoose.model('Upgrade', upgradeSchema); 

和另一个

 var mongoose = require( 'mongoose' ); var crypto = require('crypto'); var jwt = require('jsonwebtoken'); var userSchema = new mongoose.Schema({ email: { type: String, unique: true, required: true }, hero: { level: Number, name: String, type: { path: String, heroType: String }, upgrades: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Upgrade' }], unspent_xp: Number, total_xp: Number, }, armyTotal: { type: Number, default: 0, max: 5000 }, army:[{ foc_slot: String, unit_name: String, unit_cost: Number }], username: { type: String, required: true, unique: true, }, faction: String, name: { type: String, required: true }, hash: String, salt: String, roles: { type: String, default: 'player' } }); 

我正在努力做到这一点

 module.exports.profileRead = function(req, res) { User .findById(req.payload._id) .populate('hero.upgrades') .exec(function (err, user) { if (err){ console.log(err); } else { res.status(200).json(user); console.log("success"); } }); } }; 

这是一个用户的例子

 { "_id" : ObjectId("57b4b56ea03757e12c94826e"), "hash" : "76", "salt" : "2", "hero" : { "upgrades" : [ "57b42773f7cac42a21fb03f9" ], "total_xp" : 0, "unspent_xp" : 0, "type" : { "heroType" : "Psyker", "path" : "" }, "name" : "Jon Doe" }, "username" : "michaelzmyers", "faction" : "Grey Knights", "email" : "email@gmail.com", "name" : "Michael Myers", "roles" : "player", "army" : [], "armyTotal" : 625, "__v" : 3 } 

现在,我尝试了一个ObjectId的string数组,类似于这个例子,我也尝试过使用ObjectId(“STRINGHERE”),没有运气。 他们都只返回一个空的数组。 但是,如果我摆脱填充调用(或更改内容从hero.upgrades填充到英雄,或升级),那么它只是返回一个string数组。 我觉得问题是与填充和我如何使用它。 但是,当我在我的数据库(testing升级)只有一个升级,一切正常。 现在什么都没有 有什么想法吗? 如果需要,我很乐意提供更多的代码。

我发现,在我的小研究中,它将起作用:

 User .findById(req.payload._id) .populate({ path: 'hero.upgrades', model: 'Upgrade' }) .exec(function (err, user) { if (err){ console.log(err); } else { res.status(200).json(user); console.log("success"); } }); } 

它看起来像当用户给予嵌套对象符号,即hero.upgradespopulate方法,mongoose在检测引用模型时遇到问题。