[MongoDB] MongoParseError: options usecreateindex, usefindandmodify are not supported

YunJu·2023년 9월 15일

Error

목록 보기
7/10

🚫 오류메세지

  • MongoDB를 사용할 때 연결을 도와주는 몽구스를 사용할 때 발생한 오류이다.
//mongodb 연결
const mongoose = require('mongoose')
mongoose.connect('mongodb+srv://username:<password>@boilerplate.bc8rq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority', {
     useNewUrlParser: true, 
     useUnifiedTopology: true, 
     useCreateIndex: true, 
     useFindAndModify: false,
    
}).then(() => console.log('MongoDB Connected...')).catch(
    err => console.log(err))

🔧 해결방법

  • 몽구스 버전이 6.0이상이라면 MongoParseError: options usecreateindex, usefindandmodify are not supported에러가 발생한다!

  • Stack overflow 에서 몽구스 버전이 6.0이상이라면 몽구스는 항상 useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false, 로 기억하고 실행하기 때문에 더이상 지원하지 않는다. 따라서 코드 삭제나 주석처리 해주면 실행이 된다!

profile
Front-end Web Developer

0개의 댓글