【发布时间】:2021-01-07 16:32:44
【问题描述】:
我编写了一个快速函数来对 mongo atlas 数据库集合执行 GET 请求。但是,在 Postman 中对其进行测试后,我记录了以下错误:
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster.
我已经配置了我的数据库 IP 白名单,以便它可以接受来自任何 IP 的请求,如下所示: 网络访问 -> 编辑 -> 访问列表条目:0.0.0.0/0。
关于它为什么不起作用的任何建议?
这是快速路线:
app.get('/api/all-reviews', (req,res) => {
Review.find()
.then((result) => {
res.send(result)
})
.catch(err => {
console.log(err)
})
})
这是模型
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const reviewSchema = new Schema({
userName:String,
stars:String,
title:String,
photo:String,
blurb:String
}, {timestamps:true})
const Review = mongoose.model('review', reviewSchema)
module.exports = Review
这里是返回的数据示例:
id:5ff59a7a027e312bb815b3c4
userName:"testuserName"
stars:"1"
title:"title"
photo:"photoURL"
blurb:"blurb"
createdAt:2021-01-06T11:09:46.505+00:00
updatedAt:2021-01-06T11:09:46.505+00:00
【问题讨论】:
-
这能解决您的问题吗? stackoverflow.com/questions/61937581/…