未处理的承诺被拒绝

未处理的承诺被拒绝

本文介绍了猫鼬到mlab的连接问题:UnhandledPromiseRejectionWarning:未处理的承诺被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

const express = require('express');
const app = express();
const mongoose = require('mongoose');
require('./models/users');
require('./services/passport');
const authRoutes = require('./routes/authRoutes');
const Keys = require('./config/dev');

authRoutes(app);

mongoose.connect(Keys.MONGOOSE_URI);

const port = process.env.PORT || 5000;
app.listen(port);

我有一个节点快速应用程序,我尝试使用猫鼬连接到 mlab 数据库.我收到以下异常:

I have a node express application and I trying to connect to mlab db using mongoose. I am getting following exception:

我正在使用的技术堆栈:

Tech stack I am using:

"mongoose": "^4.11.1",
node: 6.11.1
npm: 4.6.1

我也尝试使用最新的猫鼬版本,但仍然是同一问题.因此我被困住了.有人可以帮忙吗?

I have tried using the latest mongoose version as well but still the same issue. I am stuck because of this. Can anybody help in this?

谢谢

推荐答案

如果您是公司法人,则必须走出来,否则您可以检查我的代码.

If you are under corporate proxy, you must have to come out else you can check my code.

 const options = {
    useMongoClient: true,
    autoIndex: false, // Don't build indexes
    reconnectTries: 100, // Never stop trying to reconnect
    reconnectInterval: 500, // Reconnect every 500ms
    poolSize: 10, // Maintain up to 10 socket connections
    // If not connected, return errors immediately rather than waiting for reconnect
    bufferMaxEntries: 0
  };
mongoose.connect('mongodb://user:[email protected]:667799/DB_NAME',options).then(
  ()=>{
    console.log("connected to mongoDB")},
 (err)=>{
     console.log("err",err);
}

)

这篇关于猫鼬到mlab的连接问题:UnhandledPromiseRejectionWarning:未处理的承诺被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:52