I am trying to save a leader board made of objects nested in an array. I want to save it in my database, but I have not been able to create the right schema and I don't think I that is the best way to go. When I run the code I get the error of:
"LeaderBoardSchema is not a constructor".
What is the appropriate way of creating a schema that I need.
I have tried many variations looking online, but I keep getting the " LeaderBoardSchema is not a constructor".
The examples from other questions on S.O have not been able to help me much.
// leaderboard object that i want to save
leaderBoard = [
leaderOne= {
name: 'Ultimate Beast',
score: 2
},
leaderTwo= {
name: 'Masked Titan',
score: 9
},
leaderThree= {
name: 'Oranolio',
score: 7
},
leaderFour= {
name: 'Popularkiya',
score:1
},
leaderFive= {
name: 'Bootecia',
score: 11
},
];
// Database schema
const Schema = mongoose.Schema()
const LeaderBoardSchema = new mongoose.Schema({
leaderBoard:{
leaderOne : {
name: String,
score: Number
},
leaderTwo : {
name: String,
score: Number
},
leaderThree : {
name: String,
score: Number
},
leaderFour : {
name: String,
score:Number
},
leaderFive : {
name: String,
score: Number
}
}
}, {collection: 'leaderboard-data'});
const PlayerData = mongoose.model('LeaderBoard Data', LeaderBoardSchema);
// My attempt
const leaderBoardToSave = new LeaderBoardSchema({
leaderBoard:{
leaderOne : {
name: 'asdf',
score: 12
},
leaderTwo : {
name: 'sfgh',
score: 12
},
leaderThree : {
name: 'weh',
score: 12
},
leaderFour : {
name: 'asdf',
score:12
},
leaderFive : {
name: 'asdf',
score: 12
}
}
})