我无法在节点API中连接到MongoDB Atlas服务器

时间:2019-11-13 20:33:37

标签: mongodb mongodb-atlas

我正在使用mongoClient.connect(在node.js中使用express),并且运行良好,直到现在,我没有进行任何改动,它就停止了工作

const express     = require('express')
const mongoClient = require('mongodb').MongoClient
const bodyParser  = require('body-parser')
const db          = require('./config/db')
const app         = express()
const routes      = require('./app/routes')
const PORT        = 8000

app.use(bodyParser.urlencoded({extended: true}))

mongoClient.connect(db.url, (err, database) => {
    if(err) return console.log(err)
    const notable = database.db('notable')
    routes(app, notable)
    app.listen(PORT, () => {
        console.log(`We're live on port ${PORT}`)
    }) 
}) 

错误消息是

{ MongoNetworkError: failed to connect to server [notable-shard-00-01-n7aon.gcp.mongodb.net:27017] on first connect [MongoNetworkError: connection 4 to notable-shard-00-01-n7aon.gcp.mongodb.net:27017 closed]
    at Pool.<anonymous> (C:\Users\filip\OneDrive\Documents\notable\backend\node_modules\mongodb\lib\core\topologies\server.js:433:11)
    at Pool.emit (events.js:189:13)
    at createConnection (C:\Users\filip\OneDrive\Documents\notable\backend\node_modules\mongodb\lib\core\connection\pool.js:562:14)
    at connect (C:\Users\filip\OneDrive\Documents\notable\backend\node_modules\mongodb\lib\core\connection\pool.js:999:9)       
    at callback (C:\Users\filip\OneDrive\Documents\notable\backend\node_modules\mongodb\lib\core\connection\connect.js:110:5)   
    at runCommand (C:\Users\filip\OneDrive\Documents\notable\backend\node_modules\mongodb\lib\core\connection\connect.js:130:7) 
    at _callback (C:\Users\filip\OneDrive\Documents\notable\backend\node_modules\mongodb\lib\core\connection\connect.js:320:5)    
    at Connection.errorHandler (C:\Users\filip\OneDrive\Documents\notable\backend\node_modules\mongodb\lib\core\connection\connect    at _callback (C:\Users\filip\OneDrive\Documents\notable\backend\node_modules\mongodb\lib\core\connection\connect.js:320:5)  
    at Connection.errorHandler (C:\Users\filip\OneDrive\Documents\notable\backend\node_modules\mongodb\lib\core\connection\connect.js:336:5)
    at Object.onceWrapper (events.js:277:13)
    at Connection.emit (events.js:189:13)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }

0 个答案:

没有答案