CollectionSlice

public class CollectionSlice<Element> : CollectionQueryable, Sequence, IteratorProtocol

A subset of data in Collection

  • The filter applied to operations in this slice

    Declaration

    Swift

    public internal(set) var filter: Query?
  • The sort specification used to get this cursor

    Declaration

    Swift

    public internal(set) var sort: Sort?
  • The projection specification used to get this cursor

    Declaration

    Swift

    public internal(set) var projection: Projection?
  • The skip used to get this cursor

    Declaration

    Swift

    public internal(set) var skip: Int?
  • The limit used to get this cursor

    Declaration

    Swift

    public internal(set) var limit: Int?
  • The cursor that points to the data

    Declaration

    Swift

    public private(set) var cursor: Cursor<Element>
  • The next found Element in the collection

    WARNING: Will return nil if unable to query the database

    Declaration

    Swift

    public func next() -> Element?
  • Iterates over all found Elements in the collection

    WARNING: Will return nil if unable to query the database

    Declaration

    Swift

    public func makeIterator() -> AnyIterator<Element>
  • An efficient and lazy forEach operation specialized for MongoDB.

    Designed to throw errors in the case of a cursor failure, unline normal for .. in cursor operations

    Declaration

    Swift

    public func forEach(_ body: (Element) throws -> Void) throws
  • Resets the cursor’s position to the beginning

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func reset() throws
  • Counts the amount of Elements matching the filter. Stops counting when the limit it reached

    For more information: https://docs.mongodb.com/manual/reference/command/count/#dbcmd.count

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func count(limitedTo limit: Int? = nil, skipping skip: Int? = nil, readConcern: ReadConcern? = nil, collation: Collation? = nil, timingOut afterTimeout: DispatchTimeInterval? = nil) throws -> Int

    Return Value

    The amount of matching Elements (without consideration of initialization success)

  • Finds Elements in this collection

    Can be used to execute DBCommands in MongoDB 2.6 and below

    For more information: https://docs.mongodb.com/manual/reference/command/find/#dbcmd.find

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func findOne(sorting sort: Sort? = nil, projecting projection: Projection? = nil, readConcern: ReadConcern? = nil, collation: Collation? = nil, skipping skip: Int? = nil) throws -> Element?

    Return Value

    The found Element

  • The first found Element in the collection

    WARNING: Will return nil if unable to query the database

    Declaration

    Swift

    public var first: Element?
  • Finds Elements in this Collection

    Can be used to execute DBCommands in MongoDB 2.6 and below. Be careful!

    For more information: https://docs.mongodb.com/manual/reference/command/find/#dbcmd.find

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func find(sorting sort: Sort? = nil, projecting projection: Projection? = nil, readConcern: ReadConcern? = nil, collation: Collation? = nil, skipping skip: Int? = nil, limitedTo limit: Int? = nil, withBatchSize batchSize: Int = 100) throws -> CollectionSlice<Element>

    Return Value

    A cursor pointing to the found Elements

  • Updates all selected Elements using a counterpart update Document.

    In most cases the $set operator is useful for updating only parts of a Document As described here: https://docs.mongodb.com/manual/reference/operator/update/set/#up._S_set

    For more information about this command: https://docs.mongodb.com/manual/reference/command/update/#dbcmd.update

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func update(to document: Document, writeConcern: WriteConcern? = nil, stoppingOnError ordered: Bool? = nil) throws -> Int
  • Removes all Documents matching the filter until the limit is reached

    For more information: https://docs.mongodb.com/manual/reference/command/delete/#dbcmd.delete

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func remove(limitedTo limit: Int = 0, writeConcern: WriteConcern? = nil, stoppingOnError ordered: Bool? = nil) throws -> Int
  • Flatmaps the containing type of this CollectionSlice lazily to another type

    Declaration

    Swift

    public func flatMap<B>(transform: @escaping (Element) throws -> (B?)) throws -> CollectionSlice<B>