본문 바로가기
  • 기록
Node.js

[Node.js] Mongoose connect option is not supported

by juserh 2022. 4. 1.

인프런 노드 리액트 강의를 보며 몽구스 사용하다 생긴 오류

const mongoose = require('mongoose')
mongoose.connect('~my connect string~',{
    useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false
}).then(()=>console.log('MongoDB Connected....'))
    .catch((err)=>console.error(err))

index.js에 위 코드를 추가하니 

MongoParseError: options usecreateindex, usefindandmodify are not supported

이와 같은 오류 메시지가 뜨며 몽고디비와 커넥트가 되지 않았다.

 

구글링하다가

https://www.mongodb.com/community/forums/t/option-usecreateindex-is-not-supported/123048

 

Option usecreateindex is not supported

I am trying to connect mongoDB to my web app but it is saying that usercreateindex is not supported please help me with this This is the code from my index.js file const express = require('express'); const app = express(); const mongoose = require('mongoos

www.mongodb.com

같은 문제에 대한 질문을 올린 글을 발견하게 되었고, 그 글에 달린 댓글에 의하면....

그렇다고 한다....

몽고디비 6버전에서는 useCreateIndex 옵션이 deprecated라고..더 이상 사용하지 않는단다.

그 외에 내가 위에 옵션으로 추가했던 useNewUrlParser, useUnifiedTopology, userCreateIndex는 항상 true 값으로 실행되고 useFindAndModify는 false 값으로 이용된다고...

 

강의를 들을 때 위 옵션을 추가하지 않으면 에러가 뜰 수 있다고 했는데..앞에 돌려보니 강의 시점 mongoose 버전이 5버전이었다.

 

그래서 결국 커넥트 할 때 넣었던 옵션 부분을 뺐더니 커넥트 성공!