Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

sort by date in mongoose throwing error for records more than 9

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){});
Problem courtesy of: Ali Hassan

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?

Solution courtesy of: Sammaye

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

sort by date in mongoose throwing error for records more than 9

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×