I am creating a REST api with a Node and MongoDB I have a Group model in this way:
'use strict'
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const GroupSchema = Schema({
name: String,
team1: String,
team2: String,
team3: String,
team4: String
})
module.exports = mongoose.model('group', GroupSchema)
In my index.js file I have a post route to save info in the model:
app.post("/api/groups", (req, res)=>{
console.log('POST /api/groups')
console.log(req.body)
let group = new Group()
group.name = req.body.name
group.team1 = req.body.team1
group.team2 = req.body.team2
group.team3 = req.body.team3
group.team4 = req.body.team4
group.save((err, groupStored) => {
if (err) res.status(500).send({message: 'Error al guardar'})
res.status(200).send({group: groupStored})
})
})
I'm testing with Postman and keeping everything right except the Name field, no matter what name you put it simply does not save values other than team1, team2, team3 and team4.
When I do console.log (req.body) it shows the complete Json object:
{
name: 'Grupo A',
team1: 'Colombia',
team2: 'Argentina',
team3: 'Peru',
team4: 'Brasil'
}
But then when checking in the BD it shows me:
{
"_id": {
"$oid": "5ad50808763e0a0488e45b7b"
},
"team1": "Egipto",
"team2": "Rusia",
"team3": "Arabia Saudita",
"team4": "Uruguay",
"__v": 0
}