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

150
Views
Why do I get mongodb.Connect is not a function when connecting to mongodb using node?

I want to connect to a mongodb database at cloud.mongodb.com using node.

I get the error mongodb.Connect is not a function. What am I doing wrong here?

const dotenv = require("dotenv");
dotenv.config();
const mongodb = require("mongodb");

const connectString = "my connection string";
mongodb.Connect(process.env.CONNECTIONSTRING, async function (err, client) {
  const db = client.db();
  const results = await db.collection("pets").find().toArray();
  console.log(results);
});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

JavaScript is case-sensitive. The function is connect, with a lower-case "c":

mongodb.connect(process.env.CONNECTIONSTRING, async function (err, client) {
  // ---^
  const db = client.db();
  const results = await db.collection("pets").find().toArray();
  console.log(results);
});
about 4 years ago · Juan Pablo Isaza Report

0

I believe this is due to one or both of these reasons:

  • You should import MongoClient and not the entire mongodb module
const { MongoClient } = require("mongodb");
  • The method name is connect and not Connect
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!