node-course-v3-code
node-course-v3-code copied to clipboard
MongoClient.connect is hung
Hello Andrew,
I am learning MongoDB from your course. I am at the section Mongodb and promises. In the video connecting and inserting the documents you had used MongoClient to conneect to the Database.
I had followed all the same steps
- installed MongoDB and placed them in appropriate folder
- Ran mongod before running the js file
- Wrote the code in js exactly as mentioned in the video
const MongoClient= mongdb.MongoClient
const connectionURL='mongodb://127.0.0.1:27017'
const database='task-manager'
MongoClient.connect(connectionURL,{useNewUrlParser:true},(error,cient)=>{
if(error){
console.log("error")
}else{
console.log("connected")
}
const db=client.db(database)
db.collection('Users').insertOne({
name:"Dushu"
})
})
ISSUE:
When I run the js file the terminal is not printing success message and the terminal is stuck. I see the mongod as request is being made as below,
{"t":{"$date":"2024-02-28T22:16:45.463+05:30"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn1","msg":"client metadata","attr":{"remote":"127.0.0.1:6843","client":"conn1","doc":{"driver":{"name":"nodejs","version":"6.3.0"},"platform":"Node.js v18.14.2, LE","os":{"name":"win32","architecture":"x64","version":"10.0.22621","type":"Windows_NT"}}}}
I there is no error and no response and no database being created as well.
MongoDB Version: 7 Node Version: v18.14.2 Mongodb npm package version: ^6.3.0
I tried downgrading mongodb, node, npm package still the issue persists. I see alot is stack over flow links and MongoDB community pages with same issue but no perfect resolution.
Could you please help me out as it is blocking the next steps in the course.
https://stackoverflow.com/questions/21848406/mongodb-node-js-client-connect-hangs https://www.mongodb.com/community/forums/t/code-hangs-on-connection/219900/3