Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Atlas Search
Created by Guest
Created on Feb 10, 2025

Sorting within nested objects. Allow filters on sort operation

Atlas search sorting currently only supports a direct sort on root level fields or nested fields indexed as type "document": https://www.mongodb.com/docs/atlas/atlas-search/sort/ Sorting cannot be done in conjunction with a filter, so a sort operation on an array of objects sorts based on the values of every document in the array. Filtering the objects inside the array and then sorting is not supported OpenSearch supports sorting with filtering: https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html#nested-sorting Here is an example of how that is done in elastic search and it would be very useful to have an equivalent feature in Atlas Search: ``` POST /_search { "query": { "nested": { "path": "parent", "query": { "bool": { "must": {"range": {"parent.age": {"gte": 21}}}, "filter": { "nested": { "path": "parent.child", "query": {"match": {"parent.child.name": "matt"}} } } } } } }, "sort" : [ { "parent.child.age" : { "mode" : "min", "order" : "asc", "nested": { "path": "parent", "filter": { "range": {"parent.age": {"gte": 21}} }, "nested": { "path": "parent.child", "filter": { "match": {"parent.child.name": "matt"} } } } } } ] } ```
  • Guest
    Feb 10, 2025
    While we have the hood open, supporting `sort mode option` would also be fantastic: https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html#_sort_mode_option