Я хочу отображать пользователей из моей базы данных в MongoDB Atlas.Я успешно создал соединение, но не могу показать пользователям.Я впервые использую MongoDB Atlas, а также Express.
На моей системе он работает отлично, с MongoDB на моей системе, но не с MongoDB Atlas.
Вот некоторые коды, которые я написал дляподключите и отобразите пользователей.
mongoose.connect("mongodb+srv://wulforr:<my password here>@cluster0-rpwjk.mongodb.net/test?retryWrites=true&w=majority" ,{useNewUrlParser: true, useCreateIndex: true})
.then(()=>{
console.log("connected to db");
})
.catch((err)=>{
console.log("error:",err);
})
let userSchema = new mongoose.Schema({
name: String,
email: String,
credits: Number
})
let User = mongoose.model("user", userSchema);
app.get("/users", function (req, res) {
// finding the information about all users from the database
User.find({}, function (err, response) {
if (err) {
console.log(err);
}
else {
res.render("users.ejs", { result: response });
}
})
})
Я дал 0.0.0.0/0 в качестве IP-адреса в MongoDB Atlas, чтобы любой мог его превзойти.
Aпредставление моей коллекции атласа MongoDB:

Ожидаемый результат:

Учитывая вывод Heroku:

Что я делаю не так?