Stage

public struct Stage: ValueConvertible

A Pipeline stage. Pipelines pass their data of the collection through every stage. The last stage defines the output.

The input are all Documents in the collection.

The input of stage 2 is the output of stage 3 and so on..

  • Allows embedding this stage inside another Document

    Declaration

    Swift

    public func makePrimitive() -> BSON.Primitive
  • The Document that this stage consists of

    Declaration

    Swift

    public func makeDocument() -> Document
  • Create a stage from a Document

    Declaration

    Swift

    public init(_ document: Document)
  • A projection stage passes only the projected fields to the next stage.

    Declaration

    Swift

    public static func project(_ projection: Projection) -> Stage
  • A match stage only passed the documents that match the query to the next stage

    Declaration

    Swift

    public static func match(_ query: Query) -> Stage
  • A match stage only passed the documents that match the query to the next stage

    Declaration

    Swift

    public static func match(_ query: Document) -> Stage
  • Takes a sample with the size of size. These randomly selected Documents will be passed to the next stage.

    Declaration

    Swift

    public static func sample(sizeOf size: Int) -> Stage
  • This will skip the specified number of input Documents and leave them out. The rest will be passed to the next stage.

    Declaration

    Swift

    public static func skip(_ skip: Int) -> Stage
  • This will limit the results to the specified number.

    The first Documents will be selected.

    Anything after that will be discarted and will not be sent to the next stage.

    Declaration

    Swift

    public static func limit(_ limit: Int) -> Stage
  • Sorts the input Documents by the specified Sort object and passed them in the newly sorted order to the next stage.

    Declaration

    Swift

    public static func sort(_ sort: Sort) -> Stage
  • Groups the input Documents by the specified expression and outputs a Document to the next stage for each distinct grouping.

    This form accepts a Document for more flexiblity.

    https://docs.mongodb.com/manual/reference/operator/aggregation/group/

    Declaration

    Swift

    public static func group(groupDocument: Document) -> Stage
  • Groups the input Documents by the specified expression and outputs a Document to the next stage for each distinct grouping.

    This form accepts predefined options and works for almost all scenarios.

    https://docs.mongodb.com/manual/reference/operator/aggregation/group/

    Declaration

    Swift

    public static func group(_ id: ExpressionRepresentable, computed computedFields: [String: AccumulatedGroupExpression] = [:]) -> Stage
  • Declaration

    Swift

    public static func unwind(_ path: String, includeArrayIndex: String? = nil, preserveNullAndEmptyArrays: Bool? = nil) -> Stage
  • Performs a left outer join to an unsharded collection in the same database

    Declaration

    Swift

    public static func lookup(from collection: String, localField: String, foreignField: String, as: String) -> Stage
  • Performs a left outer join to an unsharded collection in the same database

    Declaration

    Swift

    public static func lookup(from collection: Collection, localField: String, foreignField: String, as: String) -> Stage
  • Writes the resulting Documents to the provided Collection

    Declaration

    Swift

    public static func out(to collection: Collection) -> Stage
  • Writes the resulting Documents to the provided Collection

    Declaration

    Swift

    public static func out(to collectionName: String) -> Stage
  • Takes the input Documents and passes them through multiple Aggregation Pipelines. Every pipeline result will be placed at the provided key.

    Declaration

    Swift

    public static func facet(_ facet: [String: AggregationPipeline]) -> Stage
  • Counts the amounts of Documents that have been inputted. Places the result at the provided key.

    Declaration

    Swift

    public static func count(insertedAtKey key: String) -> Stage
  • Takes an embedded Document resulting from the provided expression and replaces the entire Document with this result.

    You can take an embedded Document at a lower level of this Document and make it the new root.

    Declaration

    Swift

    public static func replaceRoot(withExpression expression: ExpressionRepresentable) -> Stage
  • Adds fields to the inputted Documents and sends these new Documents to the next stage.

    Declaration

    Swift

    public static func addFields(_ fields: [String: ExpressionRepresentable]) -> Stage
  • Runs a geospatial query on the inputted Documents

    Outputs all documents that are near the provided location in the options matching the parameters

    Declaration

    Swift

    public static func geoNear(options: GeoNearOptions) -> Stage