I have some problem about connection to my mongoDB with 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)
})})
i get TypeError: Cannot read properties of undefined (reading 'connect').
CodePudding user response:
i think you have a typos error I can see there MnogoClient.connect
MongoClient.connect(connectionURL , {useNewUrlParser: true}, (error, client)=>{
if(error){
return console.log(error)
}
....
....
})
CodePudding user response:
const { MongoClient , ObjectID} = require('mongodb') //its Mongo not mnogo
MnogoClient (MongoClient )