728x90
🚨 발생한 문제와 상황
mode: "insensitive" 옵션이 Prisma의 일부 데이터베이스(MySQL, PostgreSQL 등)에서 지원되지 않는 문제
//팁 검색 기능 (제목, 내용, 해시태그 포함)
254 public async searchTips(query: string | null, hashtags: string[], skip: number, take: number, sort: string) {
→ 255 return await prisma.tip.findMany({
where: {
AND: [
{
OR: [
{
title: {
contains: "1",
mode: "insensitive"
}
},
{
content: {
contains: "1",
mode: "insensitive"
}
}
]
},
{
hashtags: {
some: {
hashtag: {
name: {
in: [
"#청소"
]
}
}
}
}
}
]
},
skip: 0,
take: 10,
orderBy: {
created_at: "desc"
},
include: {
media: true,
hashtags: {
include: {
hashtag: true
}
},
user: {
select: {
user_id: true,
nickname: true,
profile_image_url: true
}
},
likes: true,
saves: true
}
})
Unknown argument mode. Did you mean lte? Available options are marked with ?.
at xn (D:\\umc-h-master\\node_modules\\@prisma\\client\\runtime\\library.js:29:1363)
at Bn.handleRequestError (D:\\umc-h-master\\node_modules\\@prisma\\client\\runtime\\library.js:121:7005)
at Bn.handleAndLogRequestError (D:\\umc-h-master\\node_modules\\@prisma\\client\\runtime\\library.js:121:6686)
at Bn.request (D:\\umc-h-master\\node_modules\\@prisma\\client\\runtime\\library.js:121:6393)
at async l (D:\\umc-h-master\\node_modules\\@prisma\\client\\runtime\\library.js:130:9645)
at TipRepository.searchTips (D:\\umc-h-master\\src\\repositories\\tip.repository.ts:255:12)
at TipService.searchTips (D:\\umc-h-master\\src\\services\\tip.service.ts:234:18)
at TipController.searchTips (D:\\umc-h-master\\src\\controllers\\tip.controller.ts:823:22) {
clientVersion: '6.3.1'
}
🤔 문제의 원인 파악하기
- mode: "insensitive" 옵션은 PostgreSQL에서만 사용 가능하며, MySQL에서는 지원되지 않음.
💡해결책: MySQL에서 기본적으로 utf8_general_ci 또는 utf8mb4_general_ci 컬레이션을 사용하면, 대소문자를 구분하지 않는 검색이 가능하기 때문에 Prisma의 기본 검색 기능(contains)을 사용하면 된다.
🏃🏻♀️ 시도해본 방법
mode: "insensitive" 옵션을 제거하고, 대소문자 구분 없이 검색이 가능하도록 Prisma 기본 설정에 의존하도록 코드를 수정한다
// ✅ 팁 검색 기능 (제목, 내용, 해시태그 포함)
public async searchTips(query: string | null, hashtags: string[], skip: number, take: number, sort: string) {
return await prisma.tip.findMany({
where: {
AND: [
query
? {
OR: [
{ title: { contains: query } }, // ✅ `mode: "insensitive"` 제거
{ content: { contains: query } }
],
}
: {}, // ✅ 검색어가 없으면 무시
hashtags.length > 0
? {
hashtags: {
some: {
hashtag: {
name: { in: hashtags },
},
},
},
}
: {}, // ✅ 해시태그가 없으면 무시
],
},
skip,
take,
orderBy: this.getSortOption(sort), // ✅ 정렬 옵션 적용
include: {
media: true,
hashtags: { include: { hashtag: true } },
user: { select: { user_id: true, nickname: true, profile_image_url: true } },
likes: true,
saves: true,
},
});
}
✅ 결론
mode: "insensitive" 제거 → MySQL에서는 지원되지 않으므로 삭제
728x90
'⚡트러블 슈팅' 카테고리의 다른 글
[트러블 슈팅] AWS SDK와 Multer-S3 호환성 문제 발생 (0) | 2025.03.03 |
---|---|
[트러블 슈팅] AWS s3 이미지 깨지는 현상 (0) | 2025.03.03 |