2012-08-23 2 views
0

그래서 많은 것들을 시도한 후에 Heroku를 사용하여 내 MongoLab 서버에 연결했습니다. 유일한 문제는 내가 실제로 내 사이트로 이동하기 전에, 그것은 내게 Process exited with status 1 (아래 전체 로그)을 제공합니다. 응용 프로그램은 내 로컬 서버에서 완벽하게 실행됩니다. 아래는 app.js 코드입니다. 앱 자체는 brads-testing.herokuapp.com에 있습니다.Express Node.js 응용 프로그램이 몽구스를 사용하여 MongoLab 데이터베이스에 연결을 끊습니다

app.js :

//requires and start up app 
var express = require('express'); 
var mongoose = require('mongoose') 
    , dbURI = 'localhost/test'; 
var app = express(); 

//configures app for production, connects to mongoLab databse rather than localhost 
app.configure('production', function() { 
    //app.use(express.logger()); 
    console.log("production!"); 
    dbURI = 'mongodb://USERNAME:[email protected]:37387/test'; 
}); 

//configures app for general stuff needed 
app.configure(function() { 
    //app.use(express.logger()); 
    app.use(express.bodyParser()); 
    app.use(express.static(__dirname + '/static')); 
}); 

//tries to connect to database. If it does, connected set to true. If not, connected stays false 
var connected = false; 
mongoose.connect(dbURI); 
mongoose.connection.on('open', function() { 
    console.log("connected!"); 
    connected = true; 
    //creates new schema for object post and saves it to the database 
    var postSchema = new mongoose.Schema({ 
     body: String 
    }); 

    var Post = mongoose.model('Post', postSchema); 

    app.set('views', __dirname + '/views'); 
    app.set('view engine','jade'); 

    app.get('/', function(request, response) { 
     response.render('index'); 
    }); 

    app.post('/result', function(request, response) { 
    if (connected) { 
     var post = new Post({body: request.body.text}); 
     console.log(post); 
     post.save(function (err) { 
      if (err) { 
       console.log("error!"); 
      } else { 
       console.log("saved!"); 
      } 
     }); 

     Post.find(function (err, posts) { 
      if (!err) { 
       console.log("found!"); 
       console.log(posts); 
       response.render('result', {posts: posts}); 
      } else { 
       connected = false; 
       var error = "The server had an issue sending/executing the query..." 
       response.render('result_error', {error: error}); 
      } 
     }); 
     } else { 
     var error = "The server didn't end up connecting..." 
     response.render('result_error', {error: error}); 
     } 
    }); 

    app.get('/result', function (request, response) { 
     if (connected) { 
     Post.find(function (err, posts) { 
      if (!err) { 
       console.log("found!"); 
       console.log(posts); 
       response.render('result', {posts: posts}); 
      } else { 
       connected = false; 
       var error = "The server had an issue sending/executing the query..." 
       response.render('result_error', {error: error}); 
      } 
     }); 
     } else { 
      var errorText = "The server didn't end up connecting..." 
      response.render('result_error', {error: errorText}); 
     } 
    }); 

    app.listen(process.env.PORT || 5000); 

}); 
mongoose.connection.on('error', console.error.bind(console, 'connection error:')); 

터미널 로그 다음 connected! 메시지와 Process exited with status 1 종류의 상호 교환

2012-08-22T19:19:26+00:00 heroku[web.1]: Starting process with command `node app.js` 
2012-08-22T19:19:26+00:00 heroku[web.1]: Stopping all processes with SIGTERM 
2012-08-22T19:19:28+00:00 app[web.1]: production! 
2012-08-22T19:19:28+00:00 app[web.1]: connected! 
2012-08-22T19:19:28+00:00 heroku[web.1]: State changed from starting to up 
2012-08-22T19:19:29+00:00 heroku[web.1]: Process exited with status 1 

슬픈 일이다. 때로는 하나가 다른 하나보다 먼저 나오고 때로는 그 반대의 경우가 있습니다. 희망을 갖고 누군가가 도울 수 있기를 바랍니다.

답변

0

더 많은 로그 정보를 얻는 것이 좋을 것입니다. 일부 드라이버는 MongoDB의 모든 버전에서 작동하지 알려져있다

  • : 여기, 그 중 자신의 환경에서 시도하는 몇 가지 있습니다 대신. MongoLab은 2.0.x를 실행 중이며이 시점에서 가장 안정적인 코드 라인입니다. 그러나 우리가 2.2.x GA 릴리스의 끝 부분에있을 때 몇몇 드라이버와 특히 2.2.x의 최신 개발 릴리스가 필요한 일부 드라이버 버전이 있습니다. Mongoose가 그 중 하나인지 확실하지 않지만 MongoLab 인스턴스가 실행중인 것과 동일한 버전을 로컬에서 실행해야합니다.

  • MongoLab 데이터베이스는 인증 모드에서 실행되며 사용자에게는 명백한 보안상의 이유로 데이터베이스에 대한 권한 만 부여됩니다. 이는 일부 명령 (예 : 모든 데이터베이스 나열)이 실패 함을 의미합니다. 따라서 인증 모드에서 로컬 데이터베이스를 실행하고 관리자가 아닌 사용자로 인증 해보십시오.

+0

구체적으로 원하는 로그 정보는 무엇입니까? 로컬에서는 MongoDB 2.0.7을 실행 중이며 로컬에서 잘 작동합니다. 어디에서 MongoDB 버전에 대한 Mongoose의 의존성이 있는지 찾아야할지 모르겠습니다. auth 모드와 관련해서는'test' 데이터베이스와 연결을 설정하고 있습니다 (제가 말할 수있는 한). 그래서 문제가되어서는 안됩니다. 인증 모드에서 로컬로 데이터베이스를 실행하려면 어떻게해야합니까? –

+0

다음은 [인증 모드에서 실행 중] (http://www.mongodb.org/display/DOCS/Security+and+Authentication#SecurityandAuthentication-RunninginSecureMode%28with%5Cauthor%5CkeyFile%29)의 MongoDB 문서입니다. 로깅 사용에 대한 구체적인 권장 사항은 없지만, 0이 아닌 값으로 exit를 호출하는 이유는 무엇인지, 즉 언 래핑 된 예외 또는 오류 코드에 대한 정보를 제공해야합니다. – jared

+0

예, 표현에 대해 많이 알고 있습니까? 'express.logger()'를 활성화하고 내가 얻은 것을 볼 수 있을까요? 또한 mongodb 명령을 실행할 때까지는 mongodb localhost 데이터베이스에 액세스 할 수 없지만 그렇게 할 때까지는 쉘에 액세스 할 수 없습니다. –

관련 문제