pub(crate) fn build(self, is_group_by: bool) -> (Option<Document>, Vec<JoinStage>) {
        if self.order_bys.is_empty() {
            return (None, vec![]);
        }

        let mut order_doc = Document::new();
        let mut joins = vec![];

        for data in self.order_bys.into_iter() {
            let field = if is_group_by {
                // Explanation: All group by fields go into the _id key of the result document.
                // As it is the only point where the flat scalars are contained for the group,
                // we beed to refer to the object
                format!("_id.{}", data.scalar_field_name())
            } else {
                data.full_reference_path(false)
            };

            // Mongo: -1 -> DESC, 1 -> ASC
            match (data.sort_order(), self.reverse) {
                (SortOrder::Ascending, true) => order_doc.insert(field, -1),
                (SortOrder::Descending, true) => order_doc.insert(field, 1),
                (SortOrder::Ascending, false) => order_doc.insert(field, 1),
                (SortOrder::Descending, false) => order_doc.insert(field, -1),
            };

            joins.extend(data.join);
        }

        (Some(order_doc), joins)
    }
/// Builds and renders a Mongo sort document.
/// `is_group_by` signals that the ordering is for a grouping,
/// requiring a prefix to refer to the correct document nesting.
Builds and renders a Mongo sort document.
`is_group_by` signals that the ordering is for a grouping,
requiring a prefix to refer to the correct document nesting.
Builds and renders a Mongo sort document . ` is_group_by ` signals that the ordering is for a grouping requiring a prefix to refer to the correct document nesting .
pub(crate) fn build(self, is_group_by: bool) -> (Option<Document>, Vec<JoinStage>) {
        if self.order_bys.is_empty() {
            return (None, vec![]);
        }
        let mut order_doc = Document::new();
        let mut joins = vec![];
        for data in self.order_bys.into_iter() {
            let field = if is_group_by {
                // Explanation: All group by fields go into the _id key of the result document.
                // As it is the only point where the flat scalars are contained for the group,
                // we beed to refer to the object
                format!("_id.{}", data.scalar_field_name())
            } else {
                data.full_reference_path(false)
            };
            // Mongo: -1 -> DESC, 1 -> ASC
            match (data.sort_order(), self.reverse) {
                (SortOrder::Ascending, true) => order_doc.insert(field, -1),
                (SortOrder::Descending, true) => order_doc.insert(field, 1),
                (SortOrder::Ascending, false) => order_doc.insert(field, 1),
                (SortOrder::Descending, false) => order_doc.insert(field, -1),
            };
            joins.extend(data.join);
        }
        (Some(order_doc), joins)
    }
pub ( crate ) fn build ( self , is_group_by : bool ) -> ( Option < Document > , Vec < JoinStage > ) { if self . order_bys . is_empty ( ) { return ( None , vec ! [ ] ) ; } let mut order_doc = Document :: new ( ) ; let mut joins = vec ! [ ] ; for data in self . order_bys . into_iter ( ) { let field = if is_group_by { // Explanation: All group by fields go into the _id key of the result document. // As it is the only point where the flat scalars are contained for the group, // we beed to refer to the object format ! ( " " data scalar_field_name ( ) ) } else { data . full_reference_path ( false ) } ; // Mongo: -1 -> DESC, 1 -> ASC match ( data . sort_order ( ) , self . reverse ) { ( SortOrder :: Ascending , true ) => order_doc . insert ( field , - 1 ) , ( SortOrder :: Descending , true ) => order_doc . insert ( field , 1 ) , ( SortOrder :: Ascending , false ) => order_doc . insert ( field , 1 ) , ( SortOrder :: Descending , false ) => order_doc . insert ( field , - 1 ) , } ; joins . extend ( data . join ) ; } ( Some ( order_doc ) , joins ) }
Builds and renders a Mongo sort document.
Builds and renders a Mongo sort document .
self
is_group_by
bool