我试图在Mean中创建多对多的关系模型。
这是我到目前为止所得到的。
mongoose.connect('mongodb://localhost/team');
var Schema = mongoose.Schema
var playerSchema = new Schema(
{
name: {type:String, required:true},
position: {type: String},
game1: {type: Number},
game2: {type: Number},
},{timestamps: true}
)
mongoose.model("Player", playerSchema);
var Player = mongoose.model("Player");
var gameSchema = new Schema(
{
name:{type:String, required: true},
players: [playerSchema]
}
)
mongoose.model("Game", gameSchema);
var Game = mongoose.model("Game");
我设法在游戏中记录玩家。但这显然不完整。我无法生成关键(变量),告诉你玩家是否会参与游戏,即使他们在游戏中。需要帮忙。谢谢。