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

Issue in the server.js file mongoose.connect code #122

Open
elesq opened this issue Dec 26, 2021 · 3 comments
Open

Issue in the server.js file mongoose.connect code #122

elesq opened this issue Dec 26, 2021 · 3 comments

Comments

@elesq
Copy link

elesq commented Dec 26, 2021

The options are not supported on mongoose v6, however, it's the useCreateIndex that was completely crashing a mirror of the repo's code. Wirth updating as came close to abandoning the book as 'outdated' at such an early section (chapter 3)

@uladaharanina
Copy link

Yes, it took me a while to figure out why my connection was not working. As I understood, we need to remove this
'useCreateIndex: true' option and the connection will work.

@JimmyJoggins
Copy link

Using mongoose 6.9.1 with MongoDB 6.0.3, I was able to establish a connection by doing the following:

  1. change the IP from localhost to 127.0.0.1, and
  2. remove { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true } from the mongoose.connection() params.

config.js
const config = {
env: process.env.NODE_ENV || 'development',
port: process.env.PORT || 3000,
jwtSecret: process.env.JWT_SECRET || "YOUR_secret_key",
mongoUri: process.env.MONGODB_URI ||
process.env.MONGO_HOST ||
'mongodb://' + (process.env.IP || '127.0.0.1') + ':' + (process.env.MONGO_PORT || '27017') + '/mernproject'
}
export default config

server.js
......
// Connection URL
mongoose.Promise = global.Promise
mongoose.set('strictQuery', false);
mongoose.connect(config.mongoUri)
mongoose.connection.on('error', (err) => {
console.log('MongoDB event error: ' + err);
throw new Error(unable to connect to database: ${config.mongoUri});
})
....

@oriankeith002
Copy link

Yes, it took me a while to figure out why my connection was not working. As I understood, we need to remove this 'useCreateIndex: true' option and the connection will work.

Thanks for this tip, just solved the issue using your comment.

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

No branches or pull requests

4 participants