diff --git a/lib/controllers/agendash.js b/lib/controllers/agendash.js index ef770e8a..717d428f 100644 --- a/lib/controllers/agendash.js +++ b/lib/controllers/agendash.js @@ -6,7 +6,7 @@ module.exports = function (agenda, options) { options = options || {}; agenda.on("ready", () => { - const collection = agenda._collection.collection || agenda._collection; + const collection = agenda.db.collection || agenda._collection.collection || agenda._collection; collection.createIndexes( [ { key: { nextRunAt: -1, lastRunAt: -1, lastFinishedAt: -1 } }, @@ -20,17 +20,18 @@ module.exports = function (agenda, options) { ); // Mongoose internals changed at some point. This will fix crash for older versions. - const mdb = agenda._mdb.admin ? agenda._mdb : agenda._mdb.db; + // TODO: Need an alternative + // const mdb = agenda._mdb.admin ? agenda._mdb : agenda._mdb.db; - mdb.admin().serverInfo((error, serverInfo) => { - if (error) { - throw error; - } + // mdb.admin().serverInfo((error, serverInfo) => { + // if (error) { + // throw error; + // } - if (!semver.satisfies(semver.coerce(serverInfo.version), ">=3.6.0")) { - throw new Error("MongoDB version not supported"); - } - }); + // if (!semver.satisfies(semver.coerce(serverInfo.version), ">=3.6.0")) { + // throw new Error("MongoDB version not supported"); + // } + // }); }); // Options = {query = '', property = '', isObjectId = false, limit, skip} @@ -55,7 +56,7 @@ module.exports = function (agenda, options) { postMatch[state] = true; } - const collection = agenda._collection.collection || agenda._collection; + const collection = agenda.db.collection || agenda._collection.collection || agenda._collection; return collection .aggregate([ { $match: preMatch }, @@ -123,7 +124,7 @@ module.exports = function (agenda, options) { }; const getOverview = async () => { - const collection = agenda._collection.collection || agenda._collection; + const collection = agenda.db.collection || agenda._collection.collection || agenda._collection; const results = await collection .aggregate([ { @@ -282,7 +283,7 @@ module.exports = function (agenda, options) { return Promise.reject(new Error("Agenda instance is not ready")); } - const collection = agenda._collection.collection || agenda._collection; + const collection = agenda.db.collection || agenda._collection.collection || agenda._collection; const jobs = await collection .find({ _id: { $in: jobIds.map((jobId) => new ObjectId(jobId)) },