2

我想在 JSON 对象中填充,但它不起作用。这是代码。当我记录Group变量的响应时,我仍然得到的响应是 objectId

人口

var Groups = await GroupModel.find({ownerUser : user.battletag}).populate([
                {
                    path: "selectedInstance",
                    model: "Instances"
                },
                {
                    path: "createdAs",
                    model: "Characters",
                    populate: {
                        path: "race",
                        model: "Races"
                    }
                },
                {
                    path: "characters",
                    populate: {
                        path: "character",
                        model: "Characters"
                    }
                }
            ]).exec();

图式

var GroupSchema = new Schema({
    createdAs: {type: Schema.Types.ObjectId, ref: 'Characters'},
    description: String,
    minimumItemLevel: Number,
    voiceChat: String,
    completedAchievements: [{ type: Schema.Types.ObjectId, ref: 'Achievements' }],
    selectedInstance: { type: Schema.Types.ObjectId, ref: 'Instances' },
    instanceDifficulty: String,
    private: Boolean,
    characters: [{character: { type: Schema.Types.ObjectId, ref: 'Characters' }, role: String}],
    queue: [{ type: Schema.Types.ObjectId, ref: 'Characters' }],
    ownerUser: String,
    groupSignature: String,
    status: {type: String, default: "Open"},
    maxPlayers: Number,
    minPlayers: Number,
    expansion: String,
    createDate: {type: Date, default: Date.now}
});
4

1 回答 1

1

我已经找到了问题的解决方案,现在可以了!

 var Groups = await GroupModel.find({ownerUser : user.battletag}).populate([
            {
                path: "selectedInstance",
                model: "Instances"
            },
            {
                path: "createdAs",
                model: "Characters",
                populate: {
                    path: "race",
                    model: "Races"
                }
            },
            {
                path: "characters.character",
                model: "Characters"
            }
        ]).exec();
        return Groups
于 2018-03-03T22:32:15.703 回答