I'm using MongoDB 1.6.3, to keep a large collection (300k+ records). I added an amalgamated index.

db['collection_name'].getIndexes()
[
    {
        "name" : "_id_",
        "ns" : "db_name.event_logs",
        "key" : {
            "_id" : 1
        }
    },
    {
        "key" : {
            "updated_at.t" : -1,
            "community_id" : 1
        },
        "ns" : "db_name.event_logs",
        "background" : true,
        "name" : "updated_at.t_-1_community_id_1"
    }
]

However, after i attempt to run this code:

db['collection_name'].find({:community_id => 1}).sort(['updated_at.t', -1]).skip(@skip).limit(@limit)

i get:

Mongo::OperationFailure (an excessive amount of data for sort() without any index. add an index or specify a more compact limit)

What shall we be held doing wrong?

Try adding {community_id: 1, 'updated_at.t': -1} index. It must search by community_id first after which sort.

Therefore it "feels" like you are while using index, however the index is really an amalgamated index. I am unsure the sort is "wise enough" to make use of just the partial index.

So two problems:

  1. According to your query, I'd put community_id as part one from the index, not the 2nd. updated_at.t seems like a area which you'll do range queries. Indexes are more effective when the range totally the 2nd bit.
  2. The number of records are likely to return from community_id => 1? When the number isn't large, you might have the ability to pull off just sorting with no index.

So you might want to switch the index around and you might want to alter the sort to make use of both community_id and updated_at.t. Yes, it appears redundant, but start there and appearance the Google Groups whether it's still no longer working.

Despite a catalog, I believe you are able to get that error in case your result set surpasses 4MB.

You can observe the dimensions by starting the mongodb console and carrying this out:

show dbs
# pick yours (e.g., production)
use db-production
db.articles.stats

I wound up with results such as this:

{
"ns" : "mdalert-production.encounters",
"count" : 89077,
"size" : 62974416,
"avgObjSize" : 706.9660630690302,
"storageSize" : 85170176,
"numExtents" : 8,
"nindexes" : 6,
"lastExtentSize" : 25819648,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 18808832,
"indexSizes" : {
    "_id_" : 3719168,
    "patient_num_1" : 3440640,
    "msg_timestamp_1" : 2981888,
    "practice_id_1" : 2342912,
    "patient_id_1" : 3342336,
    "msg_timestamp_-1" : 2981888
},
"ok" : 1
}