๋ฐ์ํ
Intro
์๋
ํ์ธ์. ์ด๋ฒ์๊ฐ์๋ ์คํ๋ง๋ถํธ + mongodb MongoRepository์์ limit ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์์๋ณด๊ฒ ์ต๋๋ค.
How to solve the problem
์๋ ์ฝ๋์ ๊ฐ์ด limit() ๋ฉ์๋๋ฅผ ํ์ฉํ์ฌ ์ํ๋ count ๋งํผ ์กฐํํ ์ ์์ต๋๋ค.
suspend fun getRecentData(createAt: Instant): List<SomeDTO>? {
val query = Query()
query.with(
Sort.by(Sort.Direction.DESC, "createAt")
)
query.limit(3)
return metaHotMongoTemplate.find(query, SomeDTO::class.java, collectionName).collectList()
.awaitSingle()
}
๋ฐ์ํ