Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoClient.connect is hung #9

Open
dushu270 opened this issue Feb 28, 2024 · 1 comment
Open

MongoClient.connect is hung #9

dushu270 opened this issue Feb 28, 2024 · 1 comment

Comments

@dushu270
Copy link

dushu270 commented Feb 28, 2024

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

  1. installed MongoDB and placed them in appropriate folder
  2. Ran mongod before running the js file
  3. 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

@Abdeen26
Copy link

Abdeen26 commented Aug 7, 2024

same problem exactly with me and it works fine with async/await but doesnt work with callback approach ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants