해결된 질문
작성
·
167
0
안녕하세요 몇일전에도 schemas/index.js 관련해서 질문을 드렸습니다.
답변처럼 오타가 있어서 되지않았습니다. 답변해주셔서 감사합니다.
그런데 로컬(개인피시)에서는 정상적으로 이제 작동을 합니다. 실제 서버에 배포를 했는데, 동일 한 오류가 발생합니다.
몽고디비 계정도 만들어서 툴로도 접속이 되는데 npm start를 하면 오류가 발생합니다.
소스(./schemas/index.js)
const mongoose = require('mongoose');
const dotenv = require('dotenv');
dotenv.config();
const dbHost = process.env.DB_HOST;
const dbUser = process.env.DB_USER;
const dbPassword = process.env.DB_PASSWORD;
const dbPort = process.env.DB_PORT;
const dbName = process.env.DB_NAME;
const connect = () => {
if (process.env.NODE_ENV !== 'production') {
mongoose.set('debug', true);
}
mongoose.connect(`mongodb://${dbUser}:${dbPassword}@${dbHost}:${dbPort}/nodejs`, {
dbName: dbName,
useNewUrlParser: true,
useCreateIndex: true,
}, (error) => {
if (error) {
console.log('몽고디비 연결 에러', error);
} else {
console.log('몽고디비 연결 성공!');
}
});
};
mongoose.connection.on('error', (error) => {
console.error('몽고디비 연결 에러', error);
});
mongoose.connection.on('disconnected', () => {
console.log('몽고디비 연결이 끊겼습니다. 연결을 재시도합니다.');
connect();
});
module.exports = connect;
.env
NODE_ENV=production
PORT=3003
DB_HOST=localhost
DB_USER=nodejs
DB_PASSWORD=비밀번호
DB_PORT=27017
DB_NAME=nodejs
/etc/mongod.conf
..
net:
port: 27017
bindIp: 127.0.0.1 개인 아이피
..
security:
authorization: enabled
오류내용
RangeError: Maximum call stack size exceeded
Exception in PromiseRejectCallback:
internal/process/promises.js:102
handledRejection(promise);
^
RangeError: Maximum call stack size exceeded
Exception in PromiseRejectCallback:
internal/process/promises.js:102
handledRejection(promise);
^
RangeError: Maximum call stack size exceeded
(node:6105) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
/home/lastride25/nodejs/learn-mongoose/node_modules/mongodb/lib/utils.js:687
throw error;
^
RangeError: Maximum call stack size exceeded
at WriteStream.getColorDepth (internal/tty.js:102:23)
at console.value (internal/console/constructor.js:305:20)
at console.value (internal/console/constructor.js:322:44)
at console.log (internal/console/constructor.js:358:61)
at NativeConnection.<anonymous> (/home/lastride25/nodejs/learn-mongoose/schemas/index.js:35:13)
at NativeConnection.emit (events.js:315:20)
at NativeConnection.set (/home/lastride25/nodejs/learn-mongoose/node_modules/mongoose/lib/connection.js:128:12)
at /home/lastride25/nodejs/learn-mongoose/node_modules/mongoose/lib/connection.js:835:26
at /home/lastride25/nodejs/learn-mongoose/node_modules/mongodb/lib/utils.js:684:9
at /home/lastride25/nodejs/learn-mongoose/node_modules/mongodb/lib/mongo_client.js:226:23
at /home/lastride25/nodejs/learn-mongoose/node_modules/mongodb/lib/operations/connect.js:286:21
at parseConnectionString (/home/lastride25/nodejs/learn-mongoose/node_modules/mongodb/lib/core/uri_parser.js:615:12)
at connect (/home/lastride25/nodejs/learn-mongoose/node_modules/mongodb/lib/operations/connect.js:284:3)
at /home/lastride25/nodejs/learn-mongoose/node_modules/mongodb/lib/mongo_client.js:225:5
at maybePromise (/home/lastride25/nodejs/learn-mongoose/node_modules/mongodb/lib/utils.js:681:3)
at MongoClient.connect (/home/lastride25/nodejs/learn-mongoose/node_modules/mongodb/lib/mongo_client.js:221:10)
이와 같은 오류가 계속 발생하는 이유가 무엇일까요 ?