1
votes

There are 300 records in my mongoDB, and I do the querying with the following code :

Criteria c = ...;
Query q = new Query(c).limit(10).skip(skip);
q = q.with(new Sort(Sort.DEFAULT_DIRECTION.DESC,"fromDate"));
List<Event> results = mongoTemplate.find(q, Event.class, "Event");

When skip = 40, this code works fine.

However, when skip = 260, I get the following error:

Overflow sort stage buffered data usage of 33564943 bytes exceeds internal limit of 33554432 bytes;

It seems that mongoDB has overflow problem when sorting with large amount of records. Can anyone suggest how to deal with this issue?

1

1 Answers

1
votes

Mongodb has a 32mb limit on in memory sort: Details here:

mongo sort limit

You should be indexing your sort field, and this will fix the issue.