I am familiar with pagination-based best practices on large MongoDB collections, however I am struggling with figuring out how to split a collection in which the sort value is in a non-single field.
For example, I have a large collection of users, and there is a field for the number of times they did something. This field is unique and can have large groups of documents with the same value.
I would like to return results sorted by the 'numTimesDoneSomething' field.
Here is an example dataset:
{_id: ObjectId("50c480d81ff137e805000003"), numTimesDoneSomething: 12} {_id: ObjectId("50c480d81ff137e805000005"), numTimesDoneSomething: 9} {_id: ObjectId("50c480d81ff137e805000006"), numTimesDoneSomething: 7} {_id: ObjectId("50c480d81ff137e805000007"), numTimesDoneSomething: 1} {_id: ObjectId("50c480d81ff137e805000002"), numTimesDoneSomething: 15} {_id: ObjectId("50c480d81ff137e805000008"), numTimesDoneSomething: 1} {_id: ObjectId("50c480d81ff137e805000009"), numTimesDoneSomething: 1} {_id: ObjectId("50c480d81ff137e805000004"), numTimesDoneSomething: 12} {_id: ObjectId("50c480d81ff137e805000010"), numTimesDoneSomething: 1} {_id: ObjectId("50c480d81ff137e805000011"), numTimesDoneSomething: 1}
How can I return this dataset sorted by 'numTimesDoneSomething' with 2 records per page?
source share