Table of Contents

Method ReplaceOneAsync

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

ReplaceOneAsync(FilterDefinition<TDocument>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

public virtual Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)

Parameters

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ReplaceOneResult>

The result of the replacement.

ReplaceOneAsync(FilterDefinition<TDocument>, TDocument, UpdateOptions, CancellationToken)

Replaces a single document.

[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public virtual Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ReplaceOneResult>

The result of the replacement.

ReplaceOneAsync(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

public virtual Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)

Parameters

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ReplaceOneResult>

The result of the replacement.

ReplaceOneAsync(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, UpdateOptions, CancellationToken)

Replaces a single document.

[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public virtual Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ReplaceOneResult>

The result of the replacement.