Instance Methodmongokitten 7.9.5MongoKitten
updateOne(where:to:)
Updates a single document in this collection matching the given query with the given document.
Collection+Update.swift:13@discardableResult func updateOne(where query: Document, to document: Document) async throws -> UpdateReply
Parameters
Returns
The reply from the server
See https://docs.mongodb.com/manual/reference/command/update/
Other members in extension
Instance members
let database: MongoDatabase
The database this collection resides in
var isInTransaction: Bool
If
true
, all commands that are executed using this collection instance will be ran as part of a transaction.let name: String
The name of the collection
var namespace: MongoNamespace
The namespace of this collection, which is the database name and the collection name combined This is used for creating database commands
let session: MongoClientSession?
The session this collection is bound to. This is used for creating database commands.
var sessionId: SessionIdentifier?
The
SessionIdentifier
of the session this collection is bound to. Ifnil
, this collection is not bound to a session. This is used for creating database commands.func buildAggregate(build: () -> [AggregateBuilderStage]
) -> AggregateBuilderPipeline The
aggregate
command will create anAggregateBuilderPipeline
where data can be aggregated and be transformed in multipleAggregateBuilderStage
operationsfunc buildChangeStream(options: ChangeStreamOptions, build: () -> [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: () -> [AggregateBuilderStage]
) async throws -> ChangeStream<T> Creates a change stream for this collection using the given aggregation pipeline
func buildIndexes(build: () -> _MongoIndexes
) async throws Creates indexes based on the provided builder.
func count(Document?
) async throws -> Int Counts 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 -> Int Counts 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 throws Creates a new index by this name. If the index already exists, a new one is not created.
func createIndexes([CreateIndexes.Index]
) async throws Create 1 or more indexes on the collection.
func deleteAll(where: Document, writeConcern: WriteConcern?
) async throws -> DeleteReply Deletes 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 -> DeleteReply Deletes all documents matching the given query.
func deleteOne(where: Document, writeConcern: WriteConcern?
) async throws -> DeleteReply Deletes 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 -> DeleteReply Deletes the first document matching the given query.
func distinctValues(forKey: String, where: Document?
) async throws -> [Primitive] Returns the distinct values for the given key in this collection matching the given query.
func drop(
) async throws Drops this collection from the database it’s in and removes all documents from it.
func find(Document
) -> FindQueryBuilder Finds documents in this collection matching the given query. If no query is given, it returns all documents in the collection.
func find<Query>(Query
) -> FindQueryBuilder Finds 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
) -> FindAndModifyBuilder Modifies and returns a single document.
func findAndModify<Query>(where: Query, update: Document, remove: Bool, returnValue: FindAndModifyReturnValue
) -> FindAndModifyBuilder Modifies 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
) -> FindAndModifyBuilder Deletes a single document based on the query, returning the deleted document.
func findOneAndDelete<Query>(where: Query
) -> FindAndModifyBuilder Deletes a single document based on the query, returning the deleted document.
func findOneAndReplace(where: Document, replacement: Document, returnValue: FindAndModifyReturnValue
) -> FindAndModifyBuilder Replaces a single document based on the specified query.
func findOneAndReplace<Query>(where: Query, replacement: Document, returnValue: FindAndModifyReturnValue
) -> FindAndModifyBuilder Replaces a single document based on the specified query.
func findOneAndUpdate(where: Document, to: Document, returnValue: FindAndModifyReturnValue
) -> FindAndModifyBuilder Updates a single document based on the specified query.
func findOneAndUpdate<Query>(where: Query, to: Document, returnValue: FindAndModifyReturnValue
) -> FindAndModifyBuilder Updates a single document based on the specified query.
func findOneAndUpsert(where: Document, replacement: Document, returnValue: FindAndModifyReturnValue
) -> FindAndModifyBuilder Replaces a single document based on the specified query.
func insert(Document, writeConcern: WriteConcern?
) async throws -> InsertReply Creates 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 -> InsertReply Creates a new document in this collection with the given model encoded to a BSON Document.
func insertMany([Document], writeConcern: WriteConcern?
) async throws -> InsertReply Creates new documents in this collection with the given documents.
func insertManyEncoded<E>([E], writeConcern: WriteConcern?
) async throws -> InsertReply Creates 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 as a cursor.
func updateEncoded<E>(where: Document, to: E
) async throws -> UpdateReply Replaces 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 -> UpdateReply Updates 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 -> UpdateReply Updates all documents matching the given query.
func updateMany(where: Document, to: Document
) async throws -> UpdateReply Update all documents matching the given query with the given document.
func updateMany<Query>(where: Query, to: Document
) async throws -> UpdateReply Updates all documents matching the given query with the given document.
func updateManyEncoded<E>(where: Document, to: E
) async throws -> UpdateReply func updateManyEncoded<Query, E>(where: Query, to: E
) async throws -> UpdateReply Updates all documents matching the given query with the document encoded from the given model.
func updateOne<Query>(where: Query, to: Document
) async throws -> UpdateReply Replaces a single document in this collection matching the given query with the given document.
func upsert(Document, where: Document
) async throws -> UpdateReply Creates 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 -> UpdateReply Creates 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 -> UpdateReply Creates 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 -> UpdateReply Creates 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 change stream for this collection using the given aggregation pipeline to watch for changes
func watch<T>(options: ChangeStreamOptions, type: T.Type, using: BSONDecoder
) async throws -> ChangeStream<T> Creates a change stream for this collection using the given aggregation pipeline to watch for changes