Details
-
Improvement
-
Resolution: Done
-
Minor - P4
-
None
-
None
-
None
-
Query
Description
Currently there does not seem to be a way to sort a collection of Documents based on matched embedded document information. A possible solution would be to reuse the syntax of the $ positional matcher.
Possible Example:
doc1 : { name : "Neil", ranks : [ { name : 'fun' , score : 8 }, { name : 'smell' : score : 3 } ]
|
doc2 : { name : "Hamburger", ranks : [ { name : 'fun', score : 6 }, { name : 'smell' : score : 5 } ]
|
doc2 : { name : "Pete", ranks : [ { name : 'fun', score : 3 } ]
|
Query
docs { $query : { ranks : { $elemMatch : { name : 'smell' } } }, $orderby : { ranks.$.score : -1 }}
|
Should return basically:
[ doc2, doc1 ]
|
Could also be combined with other feature requests that would limit the document to the matched embedded document so that the $orderby could sort of off the only (or multiple) results. ( $orderby : ranks.score )