question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
IslandRhythmscommented, Jun 24, 2021

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

0reactions
Uzlopakcommented, Feb 7, 2022

@vkarpov15 I guess this issue can be closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose.connection.on('error', error => ..} TypeError:Cannot ...
This is the right way of connecting MongoDB const mongoose = require('mongoose'); var options = { promiseLibrary: require('bluebird'), ...
Read more >
TypeError: Cannot read properties of undefined ... - MongoDB
I have this code here: import { MongoClient } from "mongodb"; const createConnection = () => { // let current = null; const...
Read more >
Cannot read property '$__' of undefined when using ... - GitHub
I have the same problem, I´m using mongoose.createConnection and I want to keep using it. Anyone solve this issue?
Read more >
Mongoose v6.8.2: API docs
When no collection argument is passed, Mongoose uses the model name. ... use mongoose.set('strictQuery', false); if you want to prepare for the change....
Read more >
How to resolve a 'cannot read property connect of undefined ...
You get this error because the variable object is not defined, and trying to retrieve, set or mutate the property “id” on undefined...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found