How to resolve this error??? during mongodb connection?
const mongoClient=require('mongodb').mongoClient
const state={
db:null
}
module.exports.connect=function(done){
const url='mongodb://localhost:27017'
const dbname='shopping'
mongoClient.connect(url,(err,data)=>{
if(err) return done(err)
state.db=data.db(dbname)
done()
})
}
module.exports.get=function(){
return state.db
}
It's not mongoClient
, replace it with MongoClient
. The reason for the error is that it's case sensitive:
const MongoClient=require('mongodb').MongoClient
Also replace MongoClient.connect
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.