I have a collection of documents like this:
{
text: "Hello",
difficulty: 1
},
{
text: "Forthwith I shall not be reluctant to hinder your endeavors.",
difficulty: 509
}
I want to find the sentences that match a certain difficulty:
{
difficulty: { $in: [7, 9, 45] }
}
So far so good. But I also want to limit the number of sentences I get for each difficulty.
For example, let's say my limit is 10 for the query above: I want to get up to 10 sentences with difficulty 7, up to 10 sentences with difficulty 9, and up to 10 sentences with difficulty 45 (up to 30 sentences total).
Is there a way to do this with a mongodb query, or will I have to retrieve all of the sentences and limit them programmatically?