본문 바로가기

JS/NodeJS

(node:18436) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/4.x/docs/connections.html#use-mongo-c..

(node:18436) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/4.x/docs/connections.html#use-mongo-client


mongoose.connect(config.db_url); -> mongoose.connect(config.db_url,{userMongoClient:true});



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//데이터베이스에 연결하고 응답 객체의 속성으로 db 객체 추가
function connect(app, config) {
    console.log('connect() 호출됨.');
    
    // 데이터베이스 연결 : config의 설정 사용
    mongoose.Promise = global.Promise;  // mongoose의 Promise 객체는 global의 Promise 객체 사용하도록 함
    mongoose.connect(config.db_url,{userMongoClient:true});
    database.db = mongoose.connection;
    
    database.db.on('error'console.error.bind(console'mongoose connection error.'));    
    database.db.on('open'function () {
        console.log('데이터베이스에 연결되었습니다. : ' + config.db_url);
        
        // config에 등록된 스키마 및 모델 객체 생성
        createSchema(app, config);
        
    });
    database.db.on('disconnected', connect);
 
}
cs