Home > Net >  MongoDB Atlas with NodeJS using Mongodb is not connecting
MongoDB Atlas with NodeJS using Mongodb is not connecting

Time:09-16

I'm getting an error when I'm trying to connect with MongoDB, error pointed toward connect while it's keyword itself. I didn't know what the issue here. Error is :

mongodb.connect(
         ^

TypeError: mongodb.connect is not a function
   
let express= require('express')
let mongodb= require('mongodb').mongodb


let app = express()
let db

    let connectionString = 'mongodb srv://admin:[email protected]/ToDoApp?retryWrites=true&w=majority'
     mongodb.connect(
         connectionString,{useNewUrlParser: true}, function(err, client){
      
            db = client.db()
           
     })
    app.use(express.urlencoded({extended:false}))

CodePudding user response:

I think the reason is for that you must import MongoClient class

const MongoClient = require("mongodb").MongoClient;

reference: connect is not a function when connecting to mongodb

  • Related