部署 heroku 中的问题 - MongooseError:操作 `users.findOne()` 缓冲在 10000 毫秒后超时

时间:2021-05-06 15:47:05

标签: node.js mongodb mongoose mern

我已经在 heroku 中部署了我的 MERN 聊天应用程序,它在本地运行良好,没有任何问题,但在连接到 heroku 中的数据库时出现问题

我检查了heroku日志

My Index.js file

enter code here 
2021-05-06T14:11:10.625862+00:00 app[web.1]: memory, and will not scale past a single process.
2021-05-06T14:11:10.640277+00:00 app[web.1]: SERVER STARTED! 10334
2021-05-06T14:11:10.738745+00:00 heroku[web.1]: State changed from starting to up
2021-05-06T14:11:40.686273+00:00 app[web.1]: MongooseServerSelectionError: Could not connect to 
any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the 
database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas 
cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
2021-05-06T14:11:40.686297+00:00 app[web.1]: at NativeConnection.Connection.openUri 
(/app/node_modules/mongoose/lib/connection.js:846:32)
2021-05-06T14:11:40.686298+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:350:10
2021-05-06T14:11:40.686298+00:00 app[web.1]: at 
/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
2021-05-06T14:11:40.686299+00:00 app[web.1]: at new Promise (<anonymous>)
2021-05-06T14:11:40.686299+00:00 app[web.1]: at promiseOrCallback 
(/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
2021-05-06T14:11:40.686300+00:00 app[web.1]: at Mongoose._promiseOrCallback   
(/app/node_modules/mongoose/lib/index.js:1154:10)
2021-05-06T14:11:40.686300+00:00 app[web.1]: at Mongoose.connect 
(/app/node_modules/mongoose/lib/index.js:349:20)  
2021-05-06T14:11:40.686301+00:00 app[web.1]: at file:///app/index.js:93:3
2021-05-06T14:11:40.686301+00:00 app[web.1]: at ModuleJob.run 
(internal/modules/esm/module_job.js:152:23)
2021-05-06T14:11:40.686302+00:00 app[web.1]: at async Loader.import 
(internal/modules/esm/loader.js:166:24)
2021-05-06T14:11:40.686302+00:00 app[web.1]: at async Object.loadESM 
(internal/process/esm_loader.js:68:5) {
2021-05-06T14:11:40.686302+00:00 app[web.1]: reason: TopologyDescription {
2021-05-06T14:11:40.686303+00:00 app[web.1]: type: 'ReplicaSetNoPrimary',
2021-05-06T14:11:40.686303+00:00 app[web.1]: setName: null,
2021-05-06T14:11:40.686304+00:00 app[web.1]: maxSetVersion: null,
2021-05-06T14:11:40.686304+00:00 app[web.1]: maxElectionId: null,
2021-05-06T14:11:40.686304+00:00 app[web.1]: servers: Map(3) {
2021-05-06T14:11:40.686305+00:00 app[web.1]: 'cluster0-shard-00-01.etje3.mongodb.net:27017' => 
[ServerDescription],
2021-05-06T14:11:40.686306+00:00 app[web.1]: 'cluster0-shard-00-02.etje3.mongodb.net:27017' => 
[ServerDescription],
2021-05-06T14:11:40.686306+00:00 app[web.1]: 'cluster0-shard-00-00.etje3.mongodb.net:27017' => 
[ServerDescription]
2021-05-06T14:11:40.686307+00:00 app[web.1]: },
2021-05-06T14:11:40.686307+00:00 app[web.1]: stale: false,
2021-05-06T14:11:40.686307+00:00 app[web.1]: compatible: true,
2021-05-06T14:11:40.686308+00:00 app[web.1]: compatibilityError: null,
2021-05-06T14:11:40.686308+00:00 app[web.1]: logicalSessionTimeoutMinutes: null,
2021-05-06T14:11:40.686308+00:00 app[web.1]: heartbeatFrequencyMS: 10000,
2021-05-06T14:11:40.686309+00:00 app[web.1]: localThresholdMS: 15,
2021-05-06T14:11:40.686309+00:00 app[web.1]: commonWireVersion: null
2021-05-06T14:11:40.686309+00:00 app[web.1]: }
2021-05-06T14:11:40.686310+00:00 app[web.1]: }


2021-05-06T14:12:40.521735+00:00 app[web.1]: MongooseError: Operation `users.findOne()` 
buffering timed out after 10000ms
2021-05-06T14:12:40.521747+00:00 app[web.1]: at Timeout.<anonymous> 
(/app/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)
2021-05-06T14:12:40.521747+00:00 app[web.1]: at listOnTimeout (internal/timers.js:554:17)
2021-05-06T14:12:40.521750+00:00 app[web.1]: at processTimers (internal/timers.js:497:7)
2021-05-06T14:12:40.521786+00:00 heroku[router]: at=info method=POST path="/login" 
host=mychatapplicationmern.herokuapp.com request_id=595a5c0d-f22e-4a36-afdf-11b9579eaba1 
fwd="103.204.171.34" dyno=web.1 connect=0ms service=10012ms status=500 bytes=458 protocol=https

我遇到的两个错误

  1. MongooseError:操作 users.findOne() 缓冲在 10000 毫秒后超时
  2. MongooseServerSelectionError:无法连接到您的 MongoDB Atlas 集群中的任何服务器

对于第二个,我已经在 MongoDB 地图集中添加了我的 IP 地址,甚至可以从任何地方访问,但问题仍未解决。

我已经检查了 stackoverflow 中第一个的所有答案,但没有一个修复工作

0 个答案:

没有答案