Performance: Deleting documents
MEDIUM IMPACT
This affects server response time and client perceived speed when removing data from a database via an Express API.
app.delete('/item/:id', async (req, res) => { try { const id = req.params.id; await db.collection('items').deleteOne({ _id: new ObjectId(id) }); res.send('Deleted'); } catch { res.status(500).send('Error'); } });
app.delete('/item/:id', (req, res) => { const id = req.params.id; db.collection('items').findOneAndDelete({ _id: new ObjectId(id) }, (err, result) => { if (err) return res.status(500).send('Error'); res.send('Deleted'); }); });
| Pattern | Server Blocking | Event Loop Impact | Response Time | Verdict |
|---|---|---|---|---|
| Callback with blocking DB call | High | Blocks event loop | Slower | [X] Bad |
| Async/await non-blocking DB call | Low | Non-blocking | Faster | [OK] Good |