【发布时间】:2020-09-19 13:43:57
【问题描述】:
我对从集合中删除对象的 mongoose api 有一个奇怪的行为。
我调用了一个将 id 作为参数传递的 api(我检查了并且 ID 存在), 但我得到的是响应 404。
这里我如何使用 Angular 服务调用 api:
private deleteInvoice = 'http://localhost:3000/api/elimina_fattura';
deleteInvoices(id){
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(this.deleteInvoice+'/'+id, {headers: headers})
.map((response: Response) => response.json())
}
这里是mongoose中定义的api
app.delete('/api/elimina_fattura/:id',(req,res)=>{
Fatture.remove({_id: req.params.id})
.then(()=>{
res.json({'status':'ok'});
})
.catch((err)=>{
res.json(err);
});
});
这里是我调用 api 时的消息
我曾尝试在 robomongo 中执行相同的查询,并且似乎可以正常工作
【问题讨论】:
标签: node.js angular mongodb mongoose