'How to send an object inside an object in postman
const mongoose = require("mongoose")
const Schema = mongoose.Schema
const MonstruoSchema = Schema ({
name:String,
item:[{
arma:String
}]
})
module.exports = mongoose.model ("Monstruo",MonstruoSchema);
which is a "Monstruo" object that contains an array of items called "arma", my intention is to have a monster which can have a list of n weapons.
https://i.stack.imgur.com/tyWWH.png
I am trying to add a "arma" through postman as follows but I have not been able to get the item to add as intended
app.post("/api/monstruo",(req,res) => {
let monstruo = new Monstruo()
monstruo.name = req.body.name
monstruo.item.nombre= req.body.nombre
monstruo.save((err,monstruoGuardado)=>{
if (err) res.status(500).send("no se guardo bienn")
res.status(200).send({monstruo:monstruoGuardado})
})
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
