미니옵빠의 code stubs

MongoDB : Sort exceeded memory limit of 104857600 bytes 본문

Database/MongoDB

MongoDB : Sort exceeded memory limit of 104857600 bytes

미니옵빠 2019. 1. 18. 23:03

mongoDB 에서 aggregate 후 sort 를 할 때 요런 오류 메시지를 만날 때가 있음


MongoDB : Sort exceeded memory limit of 104857600 bytes



아래와 같이 쿼리 내 allowDiskUse 옵션을 추가하여 해결 가능


db.getCollection('hello').aggregate(

    [

      {

        $project: {

          "name": 1,

          "field_length": {$strLenCP: { $ifNull: ["name", "" ]}}

        }

      },

      {$sort: {"field_length": -1}},

      {$project: {"field_length": 0}},

    ],

    {allowDiskUse: true}

  )


참고로 Robo3T 에서 Replica Set 에 쿼리 시, 아무런 오류 메시지가 나오지 않고, 결과 없음만 뜨게 됨.

이 경우 Memory Restrictions 이슈를 의심해볼 필요가 있음.


개별 DB를 콕 찍어 쿼리를 날리면 오류 메시지가 나오긴 함.



Ref

- https://www.mkyong.com/mongodb/mongodb-sort-exceeded-memory-limit-of-104857600-bytes/

- https://docs.mongodb.com/manual/core/aggregation-pipeline-limits/#agg-memory-restrictions