Details
-
New Feature
-
Resolution: Works as Designed
-
Major - P3
-
None
-
None
-
None
-
None
Description
Correct me if I'm wrong, I believe that it is currently impossible to sort an array of sub-documents while using its index.
Take for example this collection of exactly 1 document (and imagine it has 10,000 sub-documents in the `readers` array.) The collection has an index on `readers.name`.
{_id: 1, book: "The Great Book", readers: [
{_id: 1, name: "Joe", sex: "male"},{_id: 2, name: "Jane", sex: "female"}]}
As soon as `$unwind` is used in an aggregation pipeline, the aggregation pipeline stops using all indexes.
- My first step in the aggregation pipeline would be to use `$match` to match `
{book: "The Great Book}
`.
- My second step in the aggregation pipeline would be to `$unwind` the `readers`. ====> (So, if I understand correctly, I won't be able to make use of indexes after this step!?)
- My third step in the aggregation pipeline would be to sort by `"readers.name"`. (If I understand correctly, this third step cannot make use of an index?!)</p>
Is there a different way (that I cannot see) of doing this sort without clogging the memory (by not using the index)?