I have a query function that looks like this:
(defn paginate-results [item-type which-page]
{:pre [
(= (type item-type) java.lang.String)
(= (type which-page) java.lang.String)
(= (type (Integer/parseInt which-page)) java.lang.Integer)
(or (pos? (Integer/parseInt which-page)) (zero? (Integer/parseInt which-page)))
]
:post [(= (type %) clojure.lang.LazySeq)]}
(with-collection "tma"
(find { :item-type item-type})
(fields [:item-name :item-type :user-item-name :created-at])
(sort (array-map :created-at 1 :user-item-name 1))
(limit 100)
(skip (Integer/parseInt which-page))))
At the MongoDb shell command line I do this:
> db.tma.ensureIndex( { "created-at": 1 } );
> db.tma.ensureIndex( { "user-item-name": 1 } );
> db.tma.ensureIndex( { "item-type": 1 } );
That is 1 index for the field used by "find" and also 2 indexes for the fields used by "sort".
And yet I get:
com.mongodb.MongoException: too much data for sort() with no index. add an index or specify a smaller limit
Any suggestions?