简体   繁体   English

节点,TypeError:无法读取未定义的属性(读取“连接”)。 mongoClient 连接时出错

[英]Node , TypeError: Cannot read properties of undefined (reading 'connect'). error during mongoClient connection

在此处输入图像描述

How to resolve this error???这个错误怎么解决??? during mongodb connection?在 mongodb 连接期间?

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 .它不是mongoClient ,将其替换为MongoClient The reason for the error is that it's case sensitive:错误的原因是它区分大小写:

const MongoClient=require('mongodb').MongoClient

Also replace MongoClient.connect同时替换MongoClient.connect

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未定义错误:TypeError:无法读取未定义的属性(读取“图标”) - Undefined Error: TypeError: Cannot read properties of undefined (reading 'Icon') TypeError:无法读取未定义(读取“过滤器”)和未定义错误的属性 - React - TypeError: Cannot read properties of undefined (reading 'filter') and undefined error - React 错误无法读取未定义的属性(读取“配置”)。 TypeError:无法读取未定义的属性(读取“配置”) - ERROR Cannot read properties of undefined (reading 'configurations'). TypeError: Cannot read properties of undefined (reading 'configurations') “TypeError:无法读取未定义的属性(读取'hasOwnProperty')”错误 - "TypeError: Cannot read properties of undefined (reading 'hasOwnProperty')" error Angular 12:错误类型错误:无法读取未定义的属性(读取“nativeElement”) - Angular 12: ERROR TypeError: Cannot read properties of undefined (reading 'nativeElement') 在 reactjs TypeError 中出现错误:无法读取未定义的属性(读取“过滤器”) - Getting error in reactjs TypeError: Cannot read properties of undefined (reading 'filter') 错误类型错误:无法读取未定义的属性(读取“页面”) - ERROR TypeError: Cannot read properties of undefined (reading 'page') 反应错误:“TypeError:无法读取未定义的属性(读取'props')” - react error: "TypeError: Cannot read properties of undefined (reading 'props')" 错误类型错误:无法读取未定义的属性(读取“推送”) - ERROR TypeError: Cannot read properties of undefined (reading 'push') 错误类型错误:无法读取未定义的属性(读取“项目名称”) - ERROR TypeError: Cannot read properties of undefined (reading 'ItemName')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM