0

我正在使用此模型将数据插入 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 数组都有值:mongodb 入口截图

但是当我跑步时

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正在填充,而结果中teamsteam_results没有。即使在填充之前,这些道具也不在结果中。

我如何获得teamsteam_results成为结果?

4

1 回答 1

0

更新 Typegoose 版本。我使用@hasezoey/typegoose的是 5.9 版。正确的包是@typegoose/typegoose版本 ^7.4.1。在更新 typegoose 版本后修复所有错误,它应该可以工作。

于 2020-10-29T15:39:00.160 回答