The problem is that you’re not selecting a database, hence the routes fail. Please, always check the glitch console logs to see if there are errors, try to solve them and if you still need help, come to the forum , that way you’ll learn more.
Fix:
Replace db.collection with db.db("database_name").collection:
// This is part of the code:
db.db("testdb").collection('users').findOne({ username: req.body.username }, function (err, user) {
// Here goes the rest of the code
});
db_name is the name of the database you’ve setup on the mongodb atlas or mlab.
very thankful for your reply but i am still not able to pass the challenge event after making the changes you mentioned. Can you please tell me if there is still something missing in my code -
I am still not able to understand what is the problem and has been stuck in this challenge for the past two days. Can you suggest what may be wrong in the code.