I have the following Schema (with some options taken out for simplicity):
const SubmitDebtSchema = new Schema ({
balance: [{
balanceDate: Date,
newBalance: Number
}]
});
And I have the following serverless function which posts the Schema to my database:
module.exports = async (req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "application/json");
await SubmitDebt.create(req.body)
.then(() => {
res.send(JSON.stringify({ success: true }));
})
.catch((err) => {
console.log(err);
res.send(JSON.stringify({ success: false }));
});
};
To post to my database, I have the following Axios post call:
onSubmit = async (e) => {
e.preventDefault();
const balanceDate = new Date();
await axios.post("/api/submit/submitDebt", {
balanceDate: balanceDate,
newBalance: this.state.balance,
})
this.props.history.push('/dashboard');
}
However, every time I submit the request, it just returns an empty array. The 'balance' array gets put into my database, but there's never anything in it. It just saves like this:
Can anyone point out where I'm going wrong here, and why my database entries aren't saving in my array?
It's worth pointing out - the rest of the call works fine! The entry is saved, it's just the array which is the problem.

SubmitDebt?