Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
mongoose.connect() is undefined

I'm trying to connect to my MongoDB using Mongoose and it gives me the following error.


const { mongoose } = require('mongoose');

const db = 'dburl.com/db'

mongoose.connect(db, { useNewUrlParser: true })
    .then(() => console.log('MongoDB Connected'))
    .catch((err) => console.log(err));

I get this Error

mongoose.connect(db, { useNewUrlParser: true })
         ^

TypeError: Cannot read property 'connect' of undefined
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

No need to destructure the mongoose in 1st line. Replace your 1st line of code with the below code. It should be work.

const mongoose = require('mongoose');
about 4 years ago · Juan Pablo Isaza Report

0

You should change 2 things:

  1. Change { mongoose } with mongoose
  2. Remove useNewUrlParser option. New version of Mongoose does not accept it as option and it will throw an error.
const mongoose = require('mongoose');

const db = 'dburl.com/db'

mongoose.connect(db)
    .then(() => console.log('MongoDB Connected'))
    .catch((err) => console.log(err));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!