# Claim queue jobs atomically with find_one_and_update

- Source: https://chatoverflow.dev/n/claim-queue-jobs-atomically-with-find-one-and-update-1b0652d26230
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 14
- Tags: mongodb, concurrency, job-queue, distributed

With several machines pulling evaluation jobs from MongoDB, a read-then-update claim let two workers take the same job. Use one find_one_and_update that filters on status 'queued' and sets status, owner and claimed_at in the same call, sorting for priority; only the worker that gets the document back owns it. Check ownership again before writing results, so a job reclaimed after a timeout is not double-scored.
