Agenda: Agenda cannot initialize with MongoDB Unified Topology Design

Created on 30 Jan 2020  路  16Comments  路  Source: agenda/agenda

If I set { useUnifiedTopology: true } in MongoDB connection options, Agenda will failed with error:

node_modules/agenda/lib/agenda/find-and-lock-next-job.js:26
  if (s.topology.connections().length === 0) {
                 ^

TypeError: s.topology.connections is not a function

I am using these versions:

  "dependencies": {
    "agenda": "^2.3.0",
    "mongodb": "^3.5.2"
  }

You can learn more about unified topology at http://mongodb.github.io/node-mongodb-native/3.5/reference/unified-topology/.

Thanks for your time.

Most helpful comment

Released in v3.0.0 馃帀

All 16 comments

Next issue with { useUnifiedTopology: true } is handling time out while MongoDB temporary crash

.../node_modules/agenda/lib/utils/process-jobs.js:173
        throw err;
        ^

MongoServerSelectionError: Server selection timed out after 30000 ms
    at Timeout.waitQueueMember.timer.setTimeout [as _onTimeout] (.../node_modules/mongodb/lib/core/sdam/topology.js:448:30)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)

In agenda/lib/utils/process-jobs.js file is two occurrences of throwing error and these are uncatchable and it terminates a node process. If I comment these lines it works perfectly :)

if (err) {
  debug('[%s] job lock failed while filling queue', name);
  // throw err;
  return;
}

Thanks.

I fix these issues in my fork: https://github.com/viktorzavadil/agenda.

If I add { useUnifiedTopology: true }, I get this error:

TypeError: s.topology.connections is not a function at Agenda.module.exports [as _findAndLockNextJob] (/home/lm/backend/node_modules/agenda/lib/agenda/find-and-lock-next-job.js:25:18) at jobQueueFilling (/home/lm/backend/node_modules/agenda/lib/utils/process-jobs.js:170:10) at Agenda.module.exports (/home/lm/backend/node_modules/agenda/lib/utils/process-jobs.js:32:9) at processTicksAndRejections (internal/process/task_queues.js:75:11)

If I remove { useUnifiedTopology: true }, I get deprecation this warning:

DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

I have these versions installed

"dependencies": { "agenda": "^2.3.0", "mongodb": "^3.5.2" }

Thanks

@linalimore If you want quick fix, you can download my forked version. It's working I hope without errors :smile:

@viktorzavadil may be to create PR with the fix? I'm anyway not quite sure if this repo is supported by maintainer but that would be nice to update it to work with latest mongodb driver version

@nsine I have already make PR: https://github.com/agenda/agenda/pull/921

@MichielDeMey can we get this merged? Getting the same error and I need to use [email protected]

I don't believe I can get this merged as I'm not a maintainer.

That said, PR #921 changes more than just adding support for the Unified Topology Design, which makes it more difficult to get approved/merged.

@MichielDeMey All changes are related to useUnifiedTopology option. Without it, unified topology does not work.

But, of course, Agenda is a complex library and I see only one piece of its.

How can I hasten the merge request? Can I help with it?

PR https://github.com/agenda/agenda/pull/921 is now merged in master, we will release a new version soon.
Let us know if you encounter any further issues regarding the new unified topology in the latest MongoDB driver.

Thank you, guys.

Released in v3.0.0 馃帀

I still have the same issue
MongoDB 3.6
Agenda 2.3

Node V 14.7

I am using MongoClient as the following :

MongoClient.connect(dbUrl, {useNewUrlParser: true,useUnifiedTopology: true })

If I remove useUnifiedTopology: true everything works fine even with new agenda version. So I do not get why still I get the error that supposed to be resolved in the new agenda version.

The problem happens when I am using
await agenda.every('10 minutes','process1');

From Agenda doc the initialization is as :
const agenda = new Agenda({mongo: mongoClientInstance.db('agenda-test')});

In my code :
agenda= new Agenda().mongo(client.db("myDB"),"CollectionName");

Basically I do not want to make new db for agenda and I only want to specify the collection name for agenda

Thanks

@sam13591980 sorry, didn't get with which version you have the error? v2.3 is not the latest one. And there was issues with useUnifiedTopology in it. Everything was fixed in v3+

@sam13591980 sorry, didn't get with which version you have the error? v2.3 is not the latest one. And there was issues with useUnifiedTopology in it. Everything was fixed in v3+

Thank you nsine! I used "npm update agenda" and it gave me ver 2.3 . Now, I uninstall agenda and then installed it ( ver 3.1 ) and it is working fine!
Thanks you so much!

I'm using "agenda": "^4.0.1", and still getting the deprecation error.

(node:20164) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

This is how I have initialised agenda in my file

const Agenda = require("agenda"); const mongoConnectionString = "mongodb://127.0.0.1/our-test-db"; const axios = require("axios"); const agenda = new Agenda({ db: { address: mongoConnectionString, collection: "ourScheduleCollectionName", }, });

After reading above issues, I thought the error should be fixed in the latest version.

What should I do to resolve this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vkarpov15 picture vkarpov15  路  13Comments

patrickd- picture patrickd-  路  16Comments

sumanthreddy-a picture sumanthreddy-a  路  14Comments

MMHossaini picture MMHossaini  路  23Comments

leob picture leob  路  12Comments