Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rm broken and obsolete instruction to createIndex #805

merged 1 commit into from Apr 27, 2019


None yet
2 participants
Copy link

commented Apr 27, 2019

The index is created already by default, and actually trying to run agenda._collection.createIndex(...) as instructed in the README will fail with MongoError: Index must have unique name.:

import 'dotenv/config';
import Agenda from 'agenda';
import MongoClient from 'mongodb';

(async function main() {
  const mongoClient = await MongoClient.connect(process.env.MONGO_URL, { useNewUrlParser: true });
  try {
    await mongoClient.db().dropCollection('agendaJobs');
    console.log('agendaJobs collection dropped');
  } catch (e) {
    console.log('agendaJobs collection did not exist, Agenda will create it');

  const agenda = new Agenda({
    mongo: mongoClient.db(),
  // Don't even need to await agenda._ready;
  console.log('Indexes before:', await agenda._collection.indexInformation());

  // Fails with MongoError: Index must have unique name.
  await agenda._collection.createIndex({
    disabled: 1,
    lockedAt: 1,
    name: 1,
    nextRunAt: 1,
    priority: -1
  }, {
    name: 'findAndLockNextJobIndex'

@dandv dandv requested review from wingsbob and simison Apr 27, 2019


This comment has been minimized.

Copy link
Contributor Author

commented Apr 27, 2019

See also #498


This comment has been minimized.

Copy link

commented Apr 27, 2019


@dandv dandv merged commit 1a042ce into master Apr 27, 2019

1 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
continuous-integration/travis-ci/push The Travis CI build failed
security/snyk - package.json (agenda) No manifest changes detected

@dandv dandv deleted the dandv-patch-1 branch Apr 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.