如何将对象数组放入 Mongodb 中并使用默认值?

How can i put array of objects in Mongodb with default values?

所以我在 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}
]
})

如果我保存它并在之后 console.log() 它,它会给我一个像这样的空数组???

{
  _id: new ObjectId("6270bd31ccb65e73c9c3ac03"),
  id: '542617898062053377',
  characters: [],
  __v: 0
}

我查看了文档并观看了视频教程,我什至使用了与他们相同的方法,但仍然无效。

我正在使用 MongoDb

这是代码,希望对你有帮助。 所以在模式中你必须首先传递什么类型的字符,如果你是数组然后传递默认值。

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}
  ]
}
})