Node js connect to mongodb failed

Hi @dydyyy_N_A,

Welcome to the MongoDB Community forums!

Based on the shared screenshot, it seems you are calling db.collection , but in fact, you have passed the database name in the variable dbname . That’s the reason the error is occurring for you.

Instead of db.collection , you should be calling dbname.collection
or passing the database name to the variable db .

I hope it helps!

Best regards,
Kushagra