sort by date in mongoose throwing error for records more than 9
Problem
I am getting
Error: too much data for sort() with no index
while sorting through ascending date. I only get this exception if the no of records are more than 9. Can some one tell me what I am doing wrong? or any work around?
My sorting syntax is:
image.find({reviewed:true },null,{sort:{"submittedDate":-1}}, function (err, images){});
Solution
As from the documentation here: http://www.mongodb.org/display/DOCS/Indexes#Indexes-Using{{sort%28%29}}withoutanIndex
You may use sort() to return data in order without an index if the data set to be returned is small (less than 32 Megabytes in version 2.0, or less than four megabytes in version 1.8 and earlier). For these cases it is best to use limit() and sort() together.
Is it possible that those 9 documents are actually greater than 32 megabytes? Or, as in previous versions, more than 4 megabytes?
Discussion
View additional discussion.