Class Sort


  • public class Sort
    extends Object
    Used for sorting query results or defining a sort stage in an aggregation pipeline
    Since:
    1.3
    • Constructor Detail

      • Sort

        protected Sort​(String field,
                       int order)
        Creates a sort on a field with a direction.
        • 1 to specify ascending order.
        • -1 to specify descending order.
        Parameters:
        field - the field
        order - the order
    • Method Detail

      • ascending

        public static Sort ascending​(String field)
        Creates an ascending sort on a field
        Parameters:
        field - the field
        Returns:
        the Sort instance
      • descending

        public static Sort descending​(String field)
        Creates a descending sort on a field
        Parameters:
        field - the field
        Returns:
        the Sort instance
      • naturalAscending

        public static Sort naturalAscending()
        Creates an ascending sort on a field
        Returns:
        the Sort instance
      • naturalDescending

        public static Sort naturalDescending()
        Creates a descending natural sort on a field
        Returns:
        the Sort instance
      • getOrder

        public int getOrder()
        Returns the sort order.
        • 1 for ascending order.
        • -1 for descending order.
        Returns:
        the sort order
      • getField

        public String getField()
        Returns:
        the sort field