Reputation: 1043
I have an aggregation written in a MyRepository.kt
file which is being called from MongoDataRetriever.kt
file in the backend.
MyRepository.kt
file:
import org.springframework.data.mongodb.repository.Aggregation
import org.springframework.data.mongodb.repository.MongoRepository
@Aggregation(pipeline = [
"{ \$match: { 'objName' : { \$exists: true } } }",
"{ \$sort: { 'addedDate': -1 } }"
])
fun getLatestObjectsWithLatestData(): List<MyDocument>
and MongoDataRetriever.kt
file:
override fun getLatestObjects(): List<MyObj> {
return myRepository.getLatestObjectsWithLatestData().map { it.toMyObj() }
}
The above aggregation
is failing with error:
message: "Command failed with error 16819 (Location16819): 'Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.' on serv...
So, It seems adding allowDiskUse = true
or something like that is the possible fix, but how to add that in the above annotation?
Upvotes: 3
Views: 1419
Reputation: 96
You can add @Meta(allowDiskUse = true) annotation to your method.
@Aggregation(pipeline = [
"{ \$match: { 'objName' : { \$exists: true } } }",
"{ \$sort: { 'addedDate': -1 } }"
])
@Meta(allowDiskUse = true)
fun getLatestObjectsWithLatestData(): List<MyDocument>
Upvotes: 6