模型上的 Typegoose find() 不 return 引用数组字段
Typegoose find() on model does not return reference array fields
我正在使用此模型将数据插入 mongodb:
export class Mapresult extends Typegoose {
@prop()
match_id: string;
@prop()
map: string;
@prop({ ref: Team })
winner?: Ref<Team>;
@prop()
demo_link: string;
@prop({ ref: Team })
public teams?: Ref<Team>[];
@prop({ ref: Teamresult })
public team_results?: Ref<Teamresult>[];
}
export const MapresultModel = new Mapresult().getModelForClass(Mapresult);
正在填充团队,team_results 稍后。
在 mongodb 网络界面中,两个 prop 数组都有值:screenshot of mongodb entry
但是当我运行
MapresultModel.findOne({ match_id: req.params.match_id, map: req.params.map_name })
.then((result) => {
return result.populate("winner").populate("teams").populate("team_results").execPopulate();
})
.then((result) => {
res.send(result);
});
我收到的结果是:
{
_id: 5f9843e2915f421a1866b822,
match_id: '1-96be1535-8671-4790-80ac-2bbcf1f8dfa2',
map: 'de_overpass',
demo_link: 'https://demos-europe-west2.faceit-cdn.net/csgo/4bcc5d50-e5c6-4510-a0df-1430774482af.dem.gz',
__v: 0,
winner: {
_id: 5f9843e2915f421a1866b81d,
myid: '069f67d6-a217-4635-9618-a2e8882fc678',
name: 'GoPott',
team_logo: 'https://assets.faceit-cdn.net/teams_avatars/069f67d6-a217-4635-9618-a2e8882fc678_1581456059302.jpg',
__v: 0
}
}
如您所见,winner
正在填充,而 teams
和 team_results
不在结果中。即使在填充之前,这些道具也不在结果中。
如何让 teams
和 team_results
出现在结果中?
更新Typegoose版本。我使用的是 5.9 版的 @hasezoey/typegoose
。正确的软件包是 @typegoose/typegoose
,版本为 ^7.4.1。更新typegoose版本后修复所有错误,应该可以了。
我正在使用此模型将数据插入 mongodb:
export class Mapresult extends Typegoose {
@prop()
match_id: string;
@prop()
map: string;
@prop({ ref: Team })
winner?: Ref<Team>;
@prop()
demo_link: string;
@prop({ ref: Team })
public teams?: Ref<Team>[];
@prop({ ref: Teamresult })
public team_results?: Ref<Teamresult>[];
}
export const MapresultModel = new Mapresult().getModelForClass(Mapresult);
正在填充团队,team_results 稍后。
在 mongodb 网络界面中,两个 prop 数组都有值:screenshot of mongodb entry
但是当我运行
MapresultModel.findOne({ match_id: req.params.match_id, map: req.params.map_name })
.then((result) => {
return result.populate("winner").populate("teams").populate("team_results").execPopulate();
})
.then((result) => {
res.send(result);
});
我收到的结果是:
{
_id: 5f9843e2915f421a1866b822,
match_id: '1-96be1535-8671-4790-80ac-2bbcf1f8dfa2',
map: 'de_overpass',
demo_link: 'https://demos-europe-west2.faceit-cdn.net/csgo/4bcc5d50-e5c6-4510-a0df-1430774482af.dem.gz',
__v: 0,
winner: {
_id: 5f9843e2915f421a1866b81d,
myid: '069f67d6-a217-4635-9618-a2e8882fc678',
name: 'GoPott',
team_logo: 'https://assets.faceit-cdn.net/teams_avatars/069f67d6-a217-4635-9618-a2e8882fc678_1581456059302.jpg',
__v: 0
}
}
如您所见,winner
正在填充,而 teams
和 team_results
不在结果中。即使在填充之前,这些道具也不在结果中。
如何让 teams
和 team_results
出现在结果中?
更新Typegoose版本。我使用的是 5.9 版的 @hasezoey/typegoose
。正确的软件包是 @typegoose/typegoose
,版本为 ^7.4.1。更新typegoose版本后修复所有错误,应该可以了。