在连接到我的mongoDB和MongoClient方面我遇到了一些问题。
const { MnogoClient , ObjectID} = require('mongodb')
const id = new ObjectID()
console.log(id)
const connectionURL = 'mongodb://127.0.0.1:27017'
const databaseName = 'task-manager'
MnogoClient.connect(connectionURL , {useNewUrlParser: true}, (error, client)=>{
if(error){
return console.log(error)
}
const db = client.db(databaseName)
//insertOne is asyncronuse opration and beacuse we use callback function
//for the collection we can assign my own property object id
db.collection('users').insertOne({
_id: id,
name: 'Mahdi',
age: 24
} , (error , result)=>{
if(error){
return console.log('Unable to insert the document')
}
console.log(result.ops)
})})我得到TypeError:无法读取未定义的属性(读取“连接”)。
发布于 2022-07-22 05:35:33
我想你有一个打字错误,我可以在那里看到MnogoClient.connect
MongoClient.connect(connectionURL , {useNewUrlParser: true}, (error, client)=>{
if(error){
return console.log(error)
}
....
....
})发布于 2022-07-22 06:03:40
const { MongoClient, ObjectID } = require('mongodb') // It's Mongo not mnogo
MongoClienthttps://stackoverflow.com/questions/73075393
复制相似问题