Привет, ребята, я пытаюсь загрузить массив объектов в mongoDB, и он загружает пустой массив,
это мой код:
Моя схема:
const ItemSchema = new Schema({
formName: String,
inputs: [
{
inputLabel: {
//type: String,
// required: true
},
inputType: {
// type: String,
// required: true,
// enum: ['text', 'color', 'date', 'email', 'tel', 'number']
},
inputValue: {
// type: String,
// required: true
}
}
]
});
Мой маршрут:
router.post('/', (req, res) => {
const newItem = new Item({
input: req.body,
inputLabel: req.body.inputLabel,
inputType: req.body.inputType,
inputValue: req.body.inputValue
});
newItem.save().then(item => res.json(item));
});
объект, который я пытаюсь отправить в БД:
inputs: [
{
inputLabel: 'label',
inputType: 'text',
inputValue: 'value'
}
]
это функция:
sendingData = () => {
var inputs = this.state.inputs;
console.log(inputs);
fetch('/api/items', {
method: 'POST',
body: JSON.stringify({ inputs: inputs })
});
};
его публикация без проблем, но я получаю пустой массив в моей БД, кто-нибудь знает почему?