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

mongoose.createConnection TypeError: Cannot read property 'prepare' of undefined #10377

Closed
speedtreammanga opened this issue Jun 20, 2021 · 7 comments
Assignees
Labels
underlying library issue This issue is a bug with an underlying library, like the MongoDB driver or mongodb-core

Comments

@speedtreammanga
Copy link

Do you want to request a feature or report a bug? bug
bug

What is the current behavior?
I'm getting this error:

/app/express/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:182
nodejs_1         |     authProvider.prepare(handshakeDoc, authContext, callback);
nodejs_1         |                  ^
nodejs_1         | TypeError: Cannot read property 'prepare' of undefined
nodejs_1         |     at prepareHandshakeDocument (/app/express/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:182:18)
nodejs_1         |     at performInitialHandshake (/app/express/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:87:3)
nodejs_1         |     at /app/express/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:36:5
nodejs_1         |     at callback (/app/express/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:280:5)
nodejs_1         |     at Socket.connectHandler (/app/express/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:325:5)
nodejs_1         |     at Object.onceWrapper (node:events:513:28)
nodejs_1         |     at Socket.emit (node:events:394:28)
nodejs_1         |     at Socket.emit (node:domain:470:12)
nodejs_1         |     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1119:10)

on this call: https://github.com/speedtreammanga/read-latte/blob/7947c7ef29667d681ffdc60dc377b7ab4781d15e/express/src/config/connection/connection.ts#L21

If the current behavior is a bug, please provide the steps to reproduce.
repo: https://github.com/speedtreammanga/read-latte
steps:

  • clone repo;
  • create a .env file at the root of the project with the environment variables used in my docker-compose file;
  • run cd <project root>;
  • run docker-compose build;
  • run docker-compose run;

My tsconfig.json file

What is the expected behavior?
mongoose should be able to connect to my mongodb without any issue.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

@IslandRhythms IslandRhythms added the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Jun 21, 2021
@vkarpov15 vkarpov15 modified the milestones: 5.12.15, 5.12.16 Jun 23, 2021
@speedtreammanga
Copy link
Author

@IslandRhythms did you try with an .env file with these variables?

NODE_ENV=development
NODE_PORT=8080
NODE_SECRET=dev_demo_node_secret
NODE_SESSION_SECRET=dev_demo_node_session_secret

MONGO_DB_PORT=27017
MONGO_DB_MAIN=readlatte
MONGO_DB_URI=mongodb://mongo:27017/
MONGO_ROOT_USERNAME=dev_demo_user
MONGO_ROOT_PASSWORD=dev_demo_pwd

MONGO_EXPRESS_ADMINUSERNAME=dev_demo_user
MONGO_EXPRESS_ADMINPASSWORD=dev_demo_pwd

@IslandRhythms
Copy link
Collaborator

I connected to a live database just fine, something is wrong with your setup. I think specifically it is your connection string.

@speedtreammanga
Copy link
Author

How did you managed to connect, do you have mongodb installed on your machine or ran docker run ... mongo ?
Did you do anything different than my reproduce steps ?

@speedtreammanga
Copy link
Author

speedtreammanga commented Jun 24, 2021

@IslandRhythms I have found the issue, it's a mistake on my part.
In my config.ts file I'm referencing process.env.MONGO_USERNAME and process.env.MONGO_PASSWORD but in my docker-compose I declare them as MONGO_ROOT_USERNAME & MONGO_ROOT_PASSWORD
jeez, took me forever.

Thanks for your help.

@vkarpov15 vkarpov15 removed this from the 5.12.16 milestone Jun 28, 2021
@vkarpov15 vkarpov15 reopened this Jun 30, 2021
@vkarpov15 vkarpov15 added this to the 5.13.1 milestone Jun 30, 2021
@vkarpov15 vkarpov15 added developer-experience This issue improves error messages, debugging, or reporting and removed can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. labels Jun 30, 2021
@vkarpov15
Copy link
Collaborator

We'll see if we can improve this error message, this error message is quite unhelpful.

@vkarpov15
Copy link
Collaborator

Opened an issue in the MongoDB driver ☝️ Going to remove this from our milestones but keep it open so we remember to make a note when the MongoDB driver team makes a new release.

@vkarpov15 vkarpov15 removed this from the 5.13.1 milestone Jul 1, 2021
@vkarpov15 vkarpov15 added underlying library issue This issue is a bug with an underlying library, like the MongoDB driver or mongodb-core and removed developer-experience This issue improves error messages, debugging, or reporting labels Jul 1, 2021
@Uzlopak
Copy link
Collaborator

Uzlopak commented Feb 7, 2022

@vkarpov15
I guess this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
underlying library issue This issue is a bug with an underlying library, like the MongoDB driver or mongodb-core
Projects
None yet
Development

No branches or pull requests

4 participants