Projection

public struct Projection: ValueConvertible

A projection removes any keys from it’s input Documents that have not been specified to be included except _id.

If you don’t want to include _id you’ll have to explicitely not include it.

  • Makes this Projection 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
  • An expression that can be specified to either include or exclude a field (or some custom value)

    See more

    Declaration

    Swift

    public enum ProjectionExpression: ValueConvertible, ExpressibleByBooleanLiteral, ExpressibleByStringLiteral, ExpressibleByDictionaryLiteral
  • Initializes this projection from a Document

    Declaration

    Swift

    public init(_ document: Document)
  • Supressed the _id key from being included in the projection

    Declaration

    Swift

    public mutating func suppressIdentifier()
  • Creates a BSON.Primitive from this Projection for inclusion in a Document

    Declaration

    Swift

    public func makePrimitive() -> BSON.Primitive
  • Projection can be initialized with an array of Strings. Each string represents a field that needs to be included.

    Declaration

    Swift

    public init(arrayLiteral elements: String...)
  • Projection can be initialized with a Dictionary. Each key is a String representing a key in the Documents.

    The values are an expression defining whether the key is included, excluded or has a custom value.

    Custom values are rarely used.

    Declaration

    Swift

    public init(dictionaryLiteral elements: (String, ProjectionExpression)...)