[MONGODB DRIVER] Warning: cursor.count is deprecated and will be removed in the next major version

flobeeee·2024년 3월 21일
0

시행착오

목록 보기
43/43
post-thumbnail

상황

몽고디비에서 관리하는 데이터
조건을 넣어서 검색되는 데이터 수를 res로 보내줘야함.

const filters = {USER_ID: Number(userId), MODE: "1001"};
const cursor = collection.find(filters).count();
const shotCount = await cursor

에러 메시지

[MONGODB DRIVER] Warning: cursor.count is deprecated and will be removed in the next major version, please use collection.estimatedDocumentCount or collection.countDocuments instead

해결방법


// countDocuments() 사용
const cursor = collection.countDocuments(filters);
profile
기록하는 백엔드 개발자

0개의 댓글