let database: MongoDatabaseThe database this collection belongs to
var isInTransaction: BoolWhether this collection is part of a transaction
let name: StringThe name of this collection
var namespace: MongoNamespaceThe full namespace of this collection
let session: MongoClientSession?The session this collection is bound to
var sessionId: SessionIdentifier?The session identifier for this collection’s session
func buildAggregate(build: () -> [any AggregateBuilderStage]) -> AggregateBuilderPipelineCreates an aggregation pipeline for complex data processing and analysis.
func buildChangeStream(options: ChangeStreamOptions, build: () -> [any AggregateBuilderStage]) async throws -> ChangeStream<Document>Creates a change stream for this collection using the given aggregation pipeline.
func buildChangeStream<T>(options: ChangeStreamOptions, ofType: T.Type, using: BSONDecoder, build: () -> [any AggregateBuilderStage]) async throws -> ChangeStream<T>Creates a change stream for this collection using the given aggregation pipeline
func buildIndexes(build: () -> _MongoIndexes) async throwsCreates indexes using a builder pattern
func count(Document?) async throws -> IntCounts the amount of documents in this collection matching the given query. If no query is given, this counts all documents in the collection.
func count<Query>(Query?) async throws -> IntCounts the amount of documents in this collection matching the given query. If no query is given, this counts all documents in the collection.
func createIndex(named: String, keys: Document) async throwsCreates a new index on this collection
func createIndexes([CreateIndexes.Index]) async throwsCreates multiple indexes on this collection
func deleteAll(where: Document, writeConcern: WriteConcern?) async throws -> DeleteReplyDeletes all documents matching the given query. If no query is given, it deletes all documents in the collection.
func deleteAll<Q>(where: Q, writeConcern: WriteConcern?) async throws -> DeleteReplyDeletes all documents matching the given query.
func deleteOne(where: Document, writeConcern: WriteConcern?) async throws -> DeleteReplyDeletes the first document matching the given query. If no query is given, it deletes the first document in the collection.
func deleteOne<Q>(where: Q, writeConcern: WriteConcern?) async throws -> DeleteReplyDeletes the first document matching the given query.
func distinctValues(forKey: String, where: Document?) async throws -> [any Primitive]Returns the distinct values for the given key in this collection matching the given query.
func drop() async throwsDrops this collection and all its indexes
func find(Document) -> FindQueryBuilderFinds documents in this collection matching the given query. If no query is given, it returns all documents in the collection.
func find<Query>(Query) -> FindQueryBuilderFinds documents in this collection matching the given query. If no query is given, it returns all documents in the collection.
func find<D>(Document, as: D.Type) -> MappedCursor<FindQueryBuilder, D>Finds documents in this collection matching the given query. If no query is given, it returns all documents in the collection. Decodes the results to the given type.
func find<D, Query>(Query, as: D.Type) -> MappedCursor<FindQueryBuilder, D>Finds documents in this collection matching the given query. If no query is given, it returns all documents in the collection. Decodes the results to the given type.
func findAndModify(where: Document, update: Document, remove: Bool, returnValue: FindAndModifyReturnValue) -> FindAndModifyBuilderModifies and returns a single document.
func findAndModify<Query>(where: Query, update: Document, remove: Bool, returnValue: FindAndModifyReturnValue) -> FindAndModifyBuilderModifies and returns a single document.
func findOne(Document) async throws -> Document?Finds the first document in this collection matching the given query. If no query is given, it returns the first document in the collection.
func findOne<Query>(Query) async throws -> Document?Finds the first document in this collection matching the given query. If no query is given, it returns the first document in the collection.
func findOne<D>(Document, as: D.Type) async throws -> D?Finds the first document in this collection matching the given query. Decodes the result into D.Type.
func findOne<D, Query>(Query, as: D.Type) async throws -> D?Finds the first document in this collection matching the given query. Decodes the result into D.Type.
func findOneAndDelete(where: Document) -> FindAndModifyBuilderDeletes a single document based on the query, returning the deleted document.
func findOneAndDelete<Query>(where: Query) -> FindAndModifyBuilderDeletes a single document based on the query, returning the deleted document.
func findOneAndReplace(where: Document, replacement: Document, returnValue: FindAndModifyReturnValue) -> FindAndModifyBuilderReplaces a single document based on the specified query.
func findOneAndReplace<Query>(where: Query, replacement: Document, returnValue: FindAndModifyReturnValue) -> FindAndModifyBuilderReplaces a single document based on the specified query.
func findOneAndUpdate(where: Document, to: Document, returnValue: FindAndModifyReturnValue) -> FindAndModifyBuilderUpdates a single document based on the specified query.
func findOneAndUpdate<Query>(where: Query, to: Document, returnValue: FindAndModifyReturnValue) -> FindAndModifyBuilderUpdates a single document based on the specified query.
func findOneAndUpsert(where: Document, replacement: Document, returnValue: FindAndModifyReturnValue) -> FindAndModifyBuilderReplaces a single document based on the specified query.
func insert(Document, writeConcern: WriteConcern?) async throws -> InsertReplyCreates a new document in this collection with the given document. The document must have an _id field, or one will be generated.
func insertEncoded<E>(E, writeConcern: WriteConcern?) async throws -> InsertReplyCreates a new document in this collection with the given model encoded to a BSON Document.
func insertMany([Document], writeConcern: WriteConcern?) async throws -> InsertReplyCreates new documents in this collection with the given documents.
func insertManyEncoded<E>([E], writeConcern: WriteConcern?) async throws -> InsertReplyCreates new documents in this collection with the given models encoded to BSON Documents.
func listIndexes() async throws -> MappedCursor<MongoCursor, MongoIndex>Lists all indexes in this collection
func updateEncoded<E>(where: Document, to: E) async throws -> UpdateReplyReplaces a single document in this collection matching the given query with the document encoded from the given model.
func updateEncoded<Query, E>(where: Query, to: E) async throws -> UpdateReplyUpdates a single document in this collection matching the given query with the document encoded from the given model.
func updateMany(where: Document, setting: Document?, unsetting: Document?) async throws -> UpdateReplyUpdates all documents matching the given query.
func updateMany(where: Document, to: Document) async throws -> UpdateReplyUpdate all documents matching the given query with the given document.
func updateMany<Query>(where: Query, to: Document) async throws -> UpdateReplyUpdates all documents matching the given query with the given document.
func updateManyEncoded<E>(where: Document, to: E) async throws -> UpdateReplyfunc updateOne(where: Document, to: Document) async throws -> UpdateReplyUpdates a single document in this collection matching the given query with the given document.
func updateOne<Query>(where: Query, to: Document) async throws -> UpdateReplyReplaces a single document in this collection matching the given query with the given document.
func upsert(Document, where: Document) async throws -> UpdateReplyCreates a new document in this collection if no document matches the given query. Otherwise, updates the first document matching the query.
func upsert<Query>(Document, where: Query) async throws -> UpdateReplyCreates a new document in this collection if no document matches the given query. Otherwise, updates the first document matching the query.
func upsertEncoded<Query, E>(E, where: Query) async throws -> UpdateReplyCreates a new document in this collection if no document matches the given query. Otherwise, updates the first document matching the query.
func upsertEncoded<E>(E, where: Document) async throws -> UpdateReplyCreates a new document in this collection if no document matches the given query. Otherwise, updates the first document matching the query.
func watch(options: ChangeStreamOptions) async throws -> ChangeStream<Document>Creates a simple change stream for this collection.
func watch<T>(options: ChangeStreamOptions, type: T.Type, using: BSONDecoder) async throws -> ChangeStream<T>Creates a type-safe change stream for this collection