개발자의 여의도 표류기
[Node.js] DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. 본문
Trouble Shooting
[Node.js] DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
인수은 2023. 6. 26. 18:43이런 에러가 뜨는 원인은 아래 코드에 있다.
/models/User.js
const userSchema = new mongoose.Schema({
email: { type: String, required: true, unique: true },
username: { type: String, required: true, unique: true },
password: { type: String, required: true },
name: { type: String, required: true },
address: { type: String },
});
바로 unique: true 때문이다.
이게 오래된 방식이기 때문에 새로운 방식으로 설정해주어야 한다.
/db.js
mongoose.connect("DB_ADRESS", {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
});
useCreateIndex: true 설정을 해주면 새로운 버전을 쓰게 되고 경고가 나타나지 않게 된다.
'Trouble Shooting' 카테고리의 다른 글
MacOS에서 Github.io blog 만들기 (0) | 2023.07.30 |
---|---|
[One-Key-Hidpi] 맥북 외장 모니터 배율(해상도) 조정 방법 (3) | 2021.01.02 |