So i have this Enormous Schema on Mongodb
const Schema = new mongoose.Schema({
id: {
type: String,
required: true
},
characters: [
{Lotus: Number, default: 0},
{Eclipse: Number, default: 0},
{Storm: Number, default: 0},
{Dawn: Number, default: 0},
{Lux: Number, default: 0},
{Palefire: Number, default: 0},
{Nightblade: Number, default: 0},
{Zero: Number, default: 0},
{Blast: Number, default: 0},
{Bastion: Number, default: 0},
{Astral: Number, default: 0},
{Brilliance: Number, default: 0},
{Silverfang: Number, default: 0},
{Arclight: Number, default: 0},
{Rozen: Number, default: 0},
{Qilin: Number, default: 0},
{Fate: Number, default: 0},
{Entropy: Number, default: 0},
{Luminance: Number, default: 0},
{Ember: Number, default: 0},
{Pulse: Number, default: 0},
{Tenebrion: Number, default: 0},
{Crimson_Abyss: Number, default: 0},
{Veritas: Number, default: 0},
{Plume: Number, default: 0},
{Crocotta: Number, default: 0},
{Rigor: Number, default: 0},
{Pavo: Number, default: 0},
{Laurel: Number, default: 0},
{Nier_2B: Number, default: 0},
{Nier_9S: Number, default: 0},
{Nier_A2: Number, default: 0},
{Tempest: Number, default: 0},
{Glory: Number, default: 0},
{Flare: Number, default: 0},
{Theatrical_Flame: Number, default: 0},
{Solaeter: Number, default: 0},
{Capriccio: Number, default: 0},
{Ornate_Bell: Number, default: 0},
{Remote_Star: Number, default: 0},
{Veiled_Star: Number, default: 0},
{Radiant_Daybreak: Number, default: 0}
]
})
If i save it and console.log() it afterwards, it gives me an empty array like this???
{
_id: new ObjectId("6270bd31ccb65e73c9c3ac03"),
id: '542617898062053377',
characters: [],
__v: 0
}
I checked documentation and watch video tutorials and I even used the same method they do, but still doesn't work.
I'm using MongoDb
CodePudding user response:
Here is the code , hope it will help you. So in schema you have to first pass what type of characters ,in case of your it is Array and then pass default value.
const Schema = new mongoose.Schema({
id: {
type: String,
required: true
},
characters: {
type:Array,
default:[
{Lotus: Number, default: 0},
{Eclipse: Number, default: 0},
{Storm: Number, default: 0},
{Dawn: Number, default: 0},
{Lux: Number, default: 0},
{Palefire: Number, default: 0},
{Nightblade: Number, default: 0},
{Zero: Number, default: 0},
{Blast: Number, default: 0},
{Bastion: Number, default: 0},
{Astral: Number, default: 0},
{Brilliance: Number, default: 0},
{Silverfang: Number, default: 0},
{Arclight: Number, default: 0},
{Rozen: Number, default: 0},
{Qilin: Number, default: 0},
{Fate: Number, default: 0},
{Entropy: Number, default: 0},
{Luminance: Number, default: 0},
{Ember: Number, default: 0},
{Pulse: Number, default: 0},
{Tenebrion: Number, default: 0},
{Crimson_Abyss: Number, default: 0},
{Veritas: Number, default: 0},
{Plume: Number, default: 0},
{Crocotta: Number, default: 0},
{Rigor: Number, default: 0},
{Pavo: Number, default: 0},
{Laurel: Number, default: 0},
{Nier_2B: Number, default: 0},
{Nier_9S: Number, default: 0},
{Nier_A2: Number, default: 0},
{Tempest: Number, default: 0},
{Glory: Number, default: 0},
{Flare: Number, default: 0},
{Theatrical_Flame: Number, default: 0},
{Solaeter: Number, default: 0},
{Capriccio: Number, default: 0},
{Ornate_Bell: Number, default: 0},
{Remote_Star: Number, default: 0},
{Veiled_Star: Number, default: 0},
{Radiant_Daybreak: Number, default: 0}
]
}
})