I'm trying to use the agenda package to schedule some tasks in my Nodejs project, But I'm facing some timeout issues related to the agenda package, So my question is how to make the connection property in my project? using mongoose package to make MongoDB Atlas connection how to use the existing connection of MongoDB with my agenda?
In my current code when I do some tasks it doesn't show me anything in my Atlas but I can only see the AgendaJobs collection, but inside it i can't see anything after I schedule some tasks in my Nodejs project.
How do i do things properly?
db.js:
import mongoose from 'mongoose';
import dotenv from 'dotenv';
dotenv.config();
mongoose.set('strictQuery', false);
export const MongoDBConnection = async () => {
try {
const connection = await mongoose.connect('mymongourl');
console.log('Connected to database');
return connection.connection.getClient();
} catch (err) {
console.log('Error connecting to database: ' + err);
}
};
I'm just calling this function in my index.js file like this MongoDBConnection()
Agenda Connection:
import { MongoDBConnection } from '../database/db.js';
const client = await MongoDBConnection();
const agenda = new Agenda({ mongo: client.db('AgendaJobs') });
agenda.on('ready', () => {
console.log('Schedule the task')
agenda.start();
});