Home > OS >  Problem creating a mongoose schema from a JSON file
Problem creating a mongoose schema from a JSON file

Time:12-15

Is it possible to create this JSON file structure as a mongoose schema? mongoose doesn't offer an object type and I don't know how to implement it.

{
  "Mountainbike": {
    "Cross": {
      "size": [
        "395 mm",
        "440 mm",
        "480 mm",
        "535 mm"
      ],
      "color": [
        "Himmelblau",
        "Grasgrün",
        "Stahlgrau",
        "Weinrot"
      ],
      "brake": [
        "Shimano Deore BRM6000",
        "Shimano Deore BRM7000",
        "Shimano RX810 1x11"
      ],
}
}
}

CodePudding user response:

In mongoose this will look like:

new mongoose.Schema({
  Mountainbike: {
     type: {
        Cross: {
          type: {
            size: [String],
            color: [String],
            brake: [String]
          }
        }
     }
   }
})

  • Related