I am trying to post the information to the mongoDB with Express. All connections to DB are working fine, because get Request works
In my server.js I have defined the Schema
var todoSchema = new Schema({
taskName: String,
createdAt: Date,
isDone: Boolean,
prioraty: String
}, {
collection: 'tasks'
});
var Model = mongoose.model('Model', todoSchema);
And then the app.post Request
app.post('/tasks', function(req, res) {
var savedata = new Model({
'taskName': req,
'isDone': false,
'createdAt': Date.now(),
'prioraty': 'medium'
}).save(function (err, result) {
if (err) throw err;
if (result) {
res.json(result)
}
})
});
and this doesn't work at all...
In my frontend I call it by pressing the button, but nothing happens..
postTask(task) {
return this.http.post('http://localhost:3000/tasks', task);
}
How could I fix it? As mentioned, the GET request works fine, so I hope I am on right way...
So here is get Request for example
app.get('/tasks', (req, res) => {
Model.find({
// 'request': query
}, function(err, result) {
if (err) throw err;
if (result) {
res.json(result)
} else {
res.send(JSON.stringify({
error : 'Error'
}))
}
})
});
Subscribingto it in componentangularyou are using? you shouldsubscribeyourpost requestPOSTrequest as well as a sample of thetaskobject you are sending in the post request is helpful.