Is there any solution for "n --- property 'topology' closes the circle" in Postman while working with nodejs and mongodb?
This statement was the life saver:
You must catch errors that occur in asynchronous code invoked by route handlers or middleware and pass them to Express for processing.
const getUsers = async (req, res, next) => {
let users;
try {
users = await User.find({}, '-password');
} catch (err) {
const error = new HttpError(
'Fetching users failed, please try again later.',
500
);
return next(error);
}
res.json({users: users.map(user => user.toObject({ getters: true }))});
};
It worked! After hours of searching i solved it. Also, if someone still gets stuck this is the resource http://expressjs.com/en/guide/error-handling.html where you can find answers of so many questions while working with express and nodejs.
it was occuring because i was not using async await. any mongoose operation like find() findOne, etc returns a promise and to get the proper data you should resolve it using .then(), .catch() or async await.