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

TypeError: Cannot read properties of undefined (reading 'collection') #1552

Open
andy3520 opened this issue Aug 20, 2023 · 4 comments
Open

Comments

@andy3520
Copy link

I try to init an agenda 5.x/6.x (I tried with both version)
I'm setting up agenda with agendash serve by express server and connect with mongodb atlast
Nodejs: 18.17
Agenda: 5.x/6.x (I tried with both version produce the same result)
Agendash: 4.x
Mongodb: Atlast

My Code
agendash.ts

import { Agenda } from 'agenda';
import { ENV } from '../env/index.js';

const uri = `mongodb+srv://${ENV.mongoUser}:${ENV.mongoPass}@wnba.6ldpxxb.mongodb.net/${ENV.table}?retryWrites=true&w=majority`;

export const agenda = new Agenda({
  db: {
    address: uri,
    collection: 'Jobs', <--- already insert the collection
  },
});

server.ts

import express from 'express';
import Agendash from 'agendash';
import { agenda } from './agenda/index.js';

const app = express();

app.use('/', Agendash(agenda)); // Mount Agendash middleware

const port = 3000;

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

I start the server, the agendash dashboard is display, then refresh it throw error like below and ended the server.

image

NOTES:
I already create a Jobs collections in the mongo atlast
I've tried to connect with example code from mongo and can connect successfully.

@andy3520
Copy link
Author

I remove the collection and it work by auto create another collection...., but still don't know why it didn't work when I pass the pre-create collection in

@andy3520 andy3520 reopened this Aug 20, 2023
@andy3520
Copy link
Author

I run for a while and throw the same error again, tried again with local mongodb => same result

@ksaitor
Copy link

ksaitor commented Sep 21, 2023

same problem

@RyanIgo
Copy link

RyanIgo commented Sep 28, 2023

I was having the same issue. I was initially using @hokify/agenda and swapped over to the npm i agenda and it worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants