Sort

public struct Sort: ValueConvertible, ExpressibleByDictionaryLiteral

A Sort object specifies to MongoDB in what order certain Documents need to be ordered

This can be used in normal and aggregate queries

  • Makes this Sort specification a Document

    Technically equal to makeBSONPrimtive with the main difference being that the correct type is already available without extraction

    Declaration

    Swift

    public func makeDocument() -> Document
  • Makes this Sort specification a BSONPrimtive.

    Useful for embedding in a Document

    Declaration

    Swift

    public func makePrimitive() -> BSON.Primitive
  • Helper to make mutating/reading sort specifications more accessible

    Declaration

    Swift

    public subscript(key: String) -> SortOrder?
  • Initializes a Sort object from a Dictionary literal.

    The key in the Dictionary Literal is the key you want to have sorted.

    The value in the Dictionary Literal is the SortOrder you want to use. (Usually SortOrder.ascending or SortOrder.descending)

    Declaration

    Swift

    public init(dictionaryLiteral elements: (String, SortOrder)...)
  • Initializes a custom Sort object from a Document

    Declaration

    Swift

    public init(_ document: Document)