I have an Express endpoint that you can POST to that looks like:
router.post("/add", (req, res) => {
Poll.create({
question: req.body.question,
options: req.body.options,
}).then(p => {
res.send(p);
});
});
This is what I am trying to POST:
{
"question": "what is your favourite colour?",
"options" :
[
{
"colour" : "green",
"votes" : 5
},
{
"colour": "red",
"votes": 50
}
]
}
The response I am receiving is:
{
"__v": 0,
"question": "what is your favourite colour?",
"_id": "59fe97088687d4f91c2cb647",
"options": [
{
"votes": 5,
"_id": "59fe97088687d4f91c2cb649"
},
{
"votes": 50,
"_id": "59fe97088687d4f91c2cb648"
}
]
}
For some reason the "colour" key is not being captured. I confirmed this by viewing the collection in Mongo, and indeed there is only "votes" captured and no colours.
And just in case it helps here is the Model Schema:
const PollSchema = new Schema({
question: {
type: String,
},
options: [
{
option: {
type: String,
},
votes: Number,
},
],
});
"color"in the schema. So it's being removed. You called it"option"instead.