Exemplo n.º 1
0
            /// <summary>
            /// Updates a single document in the collection according to the specified arguments.
            /// </summary>
            /// <param name="filter">
            /// A document describing the selection criteria of the update. If not specified, the first document in the
            /// collection will be updated. Can only contain
            /// <see href="https://docs.mongodb.com/manual/reference/operator/query/#query-selectors">query selector expressions</see>.
            /// </param>
            /// <param name="updateDocument">
            /// A document describing the update. Can only contain
            /// <see href="https://docs.mongodb.com/manual/reference/operator/update/#id1">update operator expressions</see>.
            /// </param>
            /// <param name="upsert">
            /// A boolean controlling whether the update should insert a document if no documents match the <paramref name="filter"/>.
            /// Defaults to <c>false</c>.
            /// </param>
            /// <returns>
            /// An awaitable <see cref="Task{T}"/> representing the remote update one operation. The result of the task
            /// contains information about the number of matched and updated documents, as well as the <c>_id</c> of the
            /// upserted document if <paramref name="upsert"/> was set to <c>true</c> and the operation resulted in an
            /// upsert.
            /// </returns>
            /// <seealso href="https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/"/>
            public async Task <UpdateResult> UpdateOneAsync(object filter, object updateDocument, bool upsert = false)
            {
                Argument.NotNull(updateDocument, nameof(updateDocument));

                var result = await _handle.UpdateOne(filter?.ToNativeJson(), updateDocument?.ToNativeJson(), upsert);

                return(result.GetValue <UpdateResult>());
            }