본문 바로가기

MongoDB

[MongoDB]DeprecationWarning: current Server Discovery and Monitoring engine is deprecated 오류 해결

(node:20552) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated,
and will be removed in a future version. To use the new Server Discover and Monitoring engine,
pass option { useUnifiedTopology: true } to the MongoClient constructor.​

 

node를 통해 mongo에 연결하다가 다음과 같은 에러가 발생했다.

검색을 해보다보니 DeprecationWarning : current~로 파생되는 경고가 두가지 있었는데

 

 

첫째, useUnifiedTopology :  true

 

둘째, useNewUrlParsar : true

 

가 있었다.

 

 

해결방법은 의외로 매우 간단했는데,

 

http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#.connect

 

MongoDB Driver API for Node.js

Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this cluster. Will ignore all changes to system collections, as well as the local, admin, and config databases.

mongodb.github.io

 

위에보면 MongoDB홈페이지에 connect에 대한 설명에 보면

MongoClient.connect(url, options, callback)

의 구조로 되어있음을 알 수 있다.

 

해당 구조에 useUnifiedTopology :true던지, useNewUrlParsar:true던지, url과 callback function 사이의 options에 해당 구문을 삽입해주면 해결된다

 

//수정전
MongoClient.connect('mongodb://localhost:27017', function (err, client) {

//수정후
MongoClient.connect('mongodb://localhost:27017',{useUnifiedTopology:true}, function (err, client) {

 


 

 

 

 

 

 

 

 

 

※Mongoose의 경우, 아래 링크와 같이 따라하면 됀다.

https://mongoosejs.com/docs/deprecations.html

 

Mongoose v5.7.10: Deprecation Warnings

Deprecation Warnings There are several deprecations in the MongoDB Node.js driver that Mongoose users should be aware of. Mongoose provides options to work around these deprecation warnings, but you need to test whether these options cause any problems for

mongoosejs.com