在 JSON 对象 Mongoose 中填充
Populate inside JSON object Mongoose
我想填充到 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}
});
我已经找到问题的解决方案,现在可以了!
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
我想填充到 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}
});
我已经找到问题的解决方案,现在可以了!
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