2017-05-23 12 views
1

私のmlabデータベースに接続しようとしていますが、次のMongoErrorを取得しています。解決方法 - MongoError:最初の接続時にサーバー[zzzzz.mlab.com:xxxx]に接続できませんでした

MongoError: failed to connect to server [zzzzz.mlab.com:xxxx] on first connect [MongoError: connect ETIMEDOUT xx.xx.xx.xxx.xxxxx

次は私のapi.jsファイルです:

const express = require('express'); 
const router = express.Router(); 
const mongoose = require('mongoose'); 
const post = require('../models/post'); 

const db = "mongodb://uname:[email protected]:xxxxx/xxxxx"; 

mongoose.Promise = global.Promise; //we add this because if we dont, you may get a warning that mongoose's default promise library is deprecated 
mongoose.connect(db, function(err) { 
    if(err) { 
     console.log('Connection error'); 
    } 
}); 

router.get('/posts', function(req, res) { 
    console.log('Requesting posts'); 
    post.find({}) 
     .exec(function(err, posts) { 
      if (err) { 
       console.log('Error getting the posts'); 
      } else { 
       res.json(posts); 
       console.log(posts); 
      } 
     }); 
}); 


module.exports = router; 

私はマングースのようなすべての依存関係をインストールしました。なぜ私はこのエラーが発生しているのか分かりません。

私はこれに関する任意のガイダンスをありがとうと思います。次のように

エラーは次のとおりです。 enter image description here

答えて

2

データベース・サーバが到達不能と思われる、あなたは資格情報、IP、およびポートが正しいことを確信していますか?

+0

私はオフィスのネットワーク上にいましたので、リクエストはパンチスルーできませんでした。それは私のホームネットワークで正常に機能しました。ありがとう – Nosail

+0

あなたのホームネットワークでのその仕事はおそらくプロキシの問題です。サーバーは、サーバー上で許可されていない必要があります。 – Dafuck

関連する問題