I am using agenda v5.0.0 with MongoDB client. I can establish connectivity but looks like the issue is with creating the index which fails. Bellow is my code structure.
agenda.ts:
import Agenda from 'agenda',
import {MongoClient} from 'mongodb',
import {cosmosDBConfig} from '../config/cosmosDBConfig';
const encodedConnectionString = encodeURIComponent(cosmosDBConfig.connectionString);
const mongoConnectionString = `mongodb://${cosmosDBConfig.username}:${encodedConnectionString}@${cosmosDBConfig.host}:${cosmosDBConfig.port}/${cosmosDBConfig.database}?ssl=${cosmosDBConfig.ssl}`;
const mongoDb = new MongoClient(mongoConnectionString).db(cosmosDBConfig.database);
const AgendaSingleton = new Agenda({
mongo: mongoDB,
db: {
address: mongoConnectionStringAgenda,
collection: cosmosDBConfig.collection,
}
sort: {nextRunAt: 1},
});
export {AgendaSingleton};
testAgenda.ts
import {AgendaSingleton} from '../utils/agenda';
AgendaSingleton.define('Test Job 1', async job => {
console.log('Test Job 1 run');
});
AgendaSingleton.every('3 minutes', 'Test Job 1');
When I run testAgenda file I get the following log "agenda:db_init index creation failed" and then the following error:
const timeout = new MongoServerSelectError(
MongoServerSelectionError: connection <monito> to [::1]:10255
)