2022. 11. 18. 17:12ㆍ백엔드 Back-end
MongooseError: Operation users.findOneAndUpdate() buffering timed out after 10000ms 해결하기
목차
- 오류 상황
- 오류 메시지
- 오류 원인
- 오류 해결
- 참고 자료
오류 상황
레파지토리 단계에서 테스트 코드를 작성하고 돌려봤는데 버퍼링 타임아웃 몽구스 에러가 발생했다. 처음에는 백엔드에서 자체적으로 디비 부하 테스트를 돌리고 있어서 그런 줄 알았다. 그런데 너무 어이없게도 원인은 다른 곳에 있었다.
오류 메시지
몽구스 에러 발생 :
MongooseError: Operation `users.findOneAndUpdate()` buffering timed out after 10000ms
at Timeout.<anonymous>
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)
오류 원인
알고 봤더니 정말 간단한 이유에서 발생한 에러였다.
MongooseError: Operation users.findOneAndUpdate() buffering timed out after 10000ms
✔︎ 몽고 디비에 연결되지 않은 상태에서 모델에 접근하려고 할때 발생하는 에러
✔︎ 몽구스를 사용하기 위해선 모든 모델이 한 번은 몽고디비에 연결되어야함
✔︎ 버퍼링 타임아웃 에러는 작업시간 초과 에러
✔︎ 버퍼링 시간 초과( 타임 아웃 ) 일반적으로 다음 상황 중 발생한다.
1️⃣ 새로운 생성된 디비에 연결에 모델 처음 등록할 때
2️⃣ mongoose.connect()을 사용할 때
This error happens because you're trying to use
a model whose connection hasn't connected to
MongoDB.
Remember that, in Mongoose,
every model has exactly one connection to MongoDB.
The buffering timeout is usually due to either
registering models on a newly created connection
but using mongoose.connect():
오류 해결
몽고 디비 연결은 app.js(진입점)에 해놓고 레파지토리에서 users 스키마를 불러놓고 열심히 실행하고 있었다. users 모델을 파일에 불렀으니까 schemas > index.js에 작성해놓은 몽구스 연결 모듈을 User 스키마에 불러주어 오류를 해결했다.
👇해결 전 코드
schemas/index.js
require('dotenv').config();
const mongoose = require('mongoose');
const connect = async () => {
await mongoose.connect(
`${process.env.MONGODB_URI}`,
{ dbName : "MY_DB" });
};
connect().catch((err) => console.log(err));
module.exports = connect;
schemas/user.js
var mongoose = require('mongoose');
const { Schema } = mongoose;
const userSchema = new Schema({
name: {
type: String
},
phoneNumber: {
type: String
},
gender: {
type: Boolean
}
}
module.exports = mongoose.model('User', userSchema);
👇해결 후 코드
schemas/user.js
var mongoose = require('mongoose');
const connect = require("../schemas");
connect();
const { Schema } = mongoose;
const userSchema = new Schema({
name: {
type: String
},
phoneNumber: {
type: String
},
gender: {
type: Boolean
}
}
module.exports = mongoose.model('User', userSchema);
참고 자료
https://masteringjs.io/tutorials/mongoose/buffering-timed-out-after-10000ms
How to Fix
Here's what the 'Buffering timed out after 10000ms' error means in Mongoose, and how to fix it.
masteringjs.io

이미지출처: https://www.nationalgeographic.com/animals/mammals/facts/mongooses
'백엔드 Back-end' 카테고리의 다른 글
최종 발표회 트러블 슈팅 정리 및 기술적 의사결정 내용 정리 (0) | 2022.12.12 |
---|---|
몽고디비 데이터 중복 판단 문제 발생 :: 트러블 슈팅 (0) | 2022.12.07 |
S3 대신 사용할 수 있는 클라우드 저장소들에 대한 고찰 : AWS S3, Cloudinary, 구글 클라우드 서비스 (0) | 2022.11.25 |
Error: listen EADDRINUSE: address already in use :::3000 에러 해결 하기 | 우분투 서버 (0) | 2022.11.16 |
multer로 이미지 전송하기 feat 서버 부하 (0) | 2022.11.13 |