【发布时间】:2019-12-30 13:14:30
【问题描述】:
我正在尝试使用 mongoose 连接到 MongoDB atlas 但总是出错,
我已尝试更改我的 IP 地址并尝试更改链接 还更改了 mongoDB altas 中的所有设置,但总是得到相同的错误
const express = require('express')
const graphqlHTTP = require('express-graphql')
const app = express()
const catSchema = require('./Schema/categorySchema')
const mongoose = require('mongoose')
// SetUp MongoDB
mongoose.connect('mongodb+srv://khawar111:khawar111@e-selling-bh1wv.mongodb.net/test?retryWrites=true&w=majority', { useNewUrlParser: true })
mongoose.connection.once('open', () => {
console.log('Database Connected')
})
mongoose.connection.on('error', (e) => {
console.log(e)
})
// Set Route for GraphQL
app.use('/graphQL', graphqlHTTP({
schema: catSchema,
graphiql: true
})
)
app.listen(3000, () => {
console.log('Server Started')
})
错误:
Error: queryTxt ETIMEOUT e-selling-bh1wv.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19) {
errno: 'ETIMEOUT',
code: 'ETIMEOUT',
syscall: 'queryTxt',
hostname: 'e-selling-bh1wv.mongodb.net'
}
(node:25313) UnhandledPromiseRejectionWarning: Error: queryTxt ETIMEOUT e-selling-bh1wv.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19)
(node:25313) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25313) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
【问题讨论】: