rschmukler/agenda — pull request #4 by vseventer (2013-11-07 23:37:25+00:00)
Title: New jobs are not or incorrectly saved.

```
var job = agenda.create('myJobHandler', {});
job.repeatEvery('10 minutes');
job.save();
```

Expected:
Job is added to the agendaJobs collection.

Actual:
An existing job is updated with `attrs` from the created job (data corruption). The new job will *not* be inserted.

Cause:
Since new jobs don’t have an `_id`, `findAndModify` executes with an empty query and thus updates the first job found. If there are no jobs yet, `findAndModify` throws: `exception: upsert mode requires query field`.

Fix:
Use `findAndModify` only if the job has an `_id`, use `insert` otherwise.