Class Sorts


  • public final class Sorts
    extends Object
    A factory for sort specifications. A convenient way to use this class is to statically import all of its methods, which allows usage like:
        collection.find().sort(orderBy(ascending("x", "y"), descending("z")))
     
    Since:
    3.0
    MongoDB documentation
    Sort
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.bson.conversions.Bson ascending​(String... fieldNames)
      Create a sort specification for an ascending sort on the given fields.
      static org.bson.conversions.Bson ascending​(List<String> fieldNames)
      Create a sort specification for an ascending sort on the given fields.
      static org.bson.conversions.Bson descending​(String... fieldNames)
      Create a sort specification for a descending sort on the given fields.
      static org.bson.conversions.Bson descending​(List<String> fieldNames)
      Create a sort specification for a descending sort on the given fields.
      static org.bson.conversions.Bson metaTextScore​(String fieldName)
      Create a sort specification for the text score meta projection on the given field.
      static org.bson.conversions.Bson orderBy​(List<? extends org.bson.conversions.Bson> sorts)
      Combine multiple sort specifications.
      static org.bson.conversions.Bson orderBy​(org.bson.conversions.Bson... sorts)
      Combine multiple sort specifications.
    • Method Detail

      • ascending

        public static org.bson.conversions.Bson ascending​(String... fieldNames)
        Create a sort specification for an ascending sort on the given fields.
        Parameters:
        fieldNames - the field names, which must contain at least one
        Returns:
        the sort specification
        MongoDB documentation
        Sort
      • ascending

        public static org.bson.conversions.Bson ascending​(List<String> fieldNames)
        Create a sort specification for an ascending sort on the given fields.
        Parameters:
        fieldNames - the field names, which must contain at least one
        Returns:
        the sort specification
        MongoDB documentation
        Sort
      • descending

        public static org.bson.conversions.Bson descending​(String... fieldNames)
        Create a sort specification for a descending sort on the given fields.
        Parameters:
        fieldNames - the field names, which must contain at least one
        Returns:
        the sort specification
        MongoDB documentation
        Sort
      • descending

        public static org.bson.conversions.Bson descending​(List<String> fieldNames)
        Create a sort specification for a descending sort on the given fields.
        Parameters:
        fieldNames - the field names, which must contain at least one
        Returns:
        the sort specification
        MongoDB documentation
        Sort
      • metaTextScore

        public static org.bson.conversions.Bson metaTextScore​(String fieldName)
        Create a sort specification for the text score meta projection on the given field.
        Parameters:
        fieldName - the field name
        Returns:
        the sort specification
        MongoDB documentation
        textScore
      • orderBy

        public static org.bson.conversions.Bson orderBy​(org.bson.conversions.Bson... sorts)
        Combine multiple sort specifications. If any field names are repeated, the last one takes precedence.
        Parameters:
        sorts - the sort specifications
        Returns:
        the combined sort specification
      • orderBy

        public static org.bson.conversions.Bson orderBy​(List<? extends org.bson.conversions.Bson> sorts)
        Combine multiple sort specifications. If any field names are repeated, the last one takes precedence.
        Parameters:
        sorts - the sort specifications
        Returns:
        the combined sort specification