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

bug fix #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions lib/controllers/agendash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand All @@ -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}
Expand All @@ -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 },
Expand Down Expand Up @@ -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([
{
Expand Down Expand Up @@ -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)) },
Expand Down