MongooseJS从其他模式填充

时间:2018-09-26 14:05:08

标签: mongoose mongoose-schema mongoose-populate

所以我有两个模型:

  1. 网球运动员(playerSchema)
  2. 匹配项列表(eventSchema)

第一个模型包含以下信息:

const playerSchema = new Schema({
    name: String,
    matches: [{
        type: Object,
        ref: 'Events'    
    }]
})

第二个模型包含以下内容:

const eventSchema = new Schema({
    event_title: String,
    matches: [{
        first_tennis_player_name: String,
        second_tennis_player_name: String,
        first_tennis_player_result: String,
        second_tennis_player_result: String
    }]
})

我想用第二个Model的数据填充matches。 伪代码将如下所示:

SELECT ALL TENNIS MATCHES WHERE FIRST_TENNIS_PLAYER_NAME OR SECOND_TENNIS_PLAYER_NAME IS NAME

0 个答案:

没有答案