Programming/Kotlin

[Kotlin] spring boot MongoDB "field locale is not valid in" error ์—๋Ÿฌ ์›์ธ ๋ฐ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

yuri lee 2025. 1. 15. 19:59
๋ฐ˜์‘ํ˜•

Intro

์•ˆ๋…•ํ•˜์„ธ์š”. spring boot + MongoDB + Kotlin ์—์„œ ์ƒˆ๋กœ์šด ์ปฌ๋ ‰์…˜ ๋‹คํ๋จผํŠธ๋ฅผ ์ถ”๊ฐ€ํ•œ ํ›„ ๋ฐ์ดํ„ฐ ์กฐํšŒ API ์‹คํ–‰ ์‹œ field locale is not valid in ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. 

 

field locale is not valid in

 

How to solve the problem

@Document(collation = "eventSpec")
class EventSpec(
    @Indexed
    var eventCode: Int?,
    var eventName: String?,
    ...
)

๊ธฐ์กด ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

 

@Document(collection = "eventSpec")
class EventSpec(
    @Indexed
    var eventCode: Int?,
    var eventName: String?,
    ...
)

์•Œ๊ณ ๋ณด๋‹ˆ collection ๋Œ€์‹ ์— collation ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์—ˆ๋”๋ผ๊ณ ์š”..

 

MongoDB์—์„œ Collation์€ ๋ฌธ์ž์—ด ๋น„๊ต์™€ ์ •๋ ฌ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐฉ์‹์„ ์ •์˜ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„, ์–ธ์–ด๋ณ„ ์ •๋ ฌ ๊ทœ์น™, ์•…์„ผํŠธ ๋ฏผ๊ฐ๋„ ๋“ฑ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค. 

 

Example

@Document(collection = "eventSpec", collation = "{ 'locale': 'en', 'strength': 2 }")
class EventSpec(
    @Indexed
    var eventCode: Int?,
    var eventName: String?,
    ...
)
  • locale: 'en': ์˜์–ด ์ง€์—ญ์˜ ์ •๋ ฌ ๊ทœ์น™ ์ ์šฉ
  • strength: 2: ๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„ ์—†์ด ๋น„๊ต ์ˆ˜ํ–‰
๋ฐ˜์‘ํ˜•