Class Sort

  • Direct Known Subclasses:
    Sort

    public class Sort
    extends java.lang.Object
    Used for sorting query results or defining a sort stage in an aggregation pipeline
    Since:
    1.3
    MongoDB documentation
    reference/operator/aggregation/sort/ $sort
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Sort​(java.lang.String field, int order)
      Creates a sort on a field with a direction.
    • Constructor Detail

      • Sort

        protected Sort​(java.lang.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​(java.lang.String field)
        Creates an ascending sort on a field
        Parameters:
        field - the field
        Returns:
        the Sort instance
      • descending

        public static Sort descending​(java.lang.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 java.lang.String getField()
        Returns:
        the sort field