79456213

Date: 2025-02-21 02:04:03
Score: 1.5
Natty:
Report link

Turns out it wasn’t actually hanging—the findOne inside a loop of over 2000 items was just extremely slow. I figured this out by adding mongoose.set("debug", true); after mongoose.connect(), which revealed that Mongoose was making a separate query for each vacancy, causing a massive slowdown.

The fix was simple: instead of querying the database repeatedly, I fetched all existing entries at once using Model.find({}, "vacancyId") and stored them in an array for fast lookups in memory.

Reasons:
  • No code block (0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Emiliano