Table of Contents

Class FindOperation<TDocument>

Namespace
MongoDB.Driver.Core.Operations
Assembly
MongoDB.Driver.Core.dll

Represents a Find command operation.

public class FindOperation<TDocument> : IReadOperation<IAsyncCursor<TDocument>>, IExecutableInRetryableReadContext<IAsyncCursor<TDocument>>, IExplainableOperation

Type Parameters

TDocument

The type of the document.

Inheritance
FindOperation<TDocument>
Implements
Inherited Members
Extension Methods

Constructors

FindOperation(CollectionNamespace, IBsonSerializer<TDocument>, MessageEncoderSettings)

Initializes a new instance of the FindOperation<TDocument> class.

public FindOperation(CollectionNamespace collectionNamespace, IBsonSerializer<TDocument> resultSerializer, MessageEncoderSettings messageEncoderSettings)

Parameters

collectionNamespace CollectionNamespace

The collection namespace.

resultSerializer IBsonSerializer<TDocument>

The result serializer.

messageEncoderSettings MessageEncoderSettings

The message encoder settings.

Properties

AllowDiskUse

Gets or sets a value indicating whether the server is allowed to write to disk while executing the Find operation.

public bool? AllowDiskUse { get; set; }

Property Value

bool?

true if the server is allowed to write to disk while executing the Find operation; otherwise, false.

AllowPartialResults

Gets or sets a value indicating whether the server is allowed to return partial results if any shards are unavailable.

public bool? AllowPartialResults { get; set; }

Property Value

bool?

true if the server is allowed to return partial results if any shards are unavailable; otherwise, false.

BatchSize

Gets or sets the size of a batch.

public int? BatchSize { get; set; }

Property Value

int?

The size of a batch.

Collation

Gets or sets the collation.

public Collation Collation { get; set; }

Property Value

Collation

The collation.

CollectionNamespace

Gets the collection namespace.

public CollectionNamespace CollectionNamespace { get; }

Property Value

CollectionNamespace

The collection namespace.

Comment

Gets or sets the comment.

public BsonValue Comment { get; set; }

Property Value

BsonValue

The comment.

CursorType

Gets or sets the type of the cursor.

public CursorType CursorType { get; set; }

Property Value

CursorType

The type of the cursor.

Filter

Gets or sets the filter.

public BsonDocument Filter { get; set; }

Property Value

BsonDocument

The filter.

FirstBatchSize

Gets or sets the size of the first batch.

public int? FirstBatchSize { get; set; }

Property Value

int?

The size of the first batch.

Hint

Gets or sets the hint.

public BsonValue Hint { get; set; }

Property Value

BsonValue

The hint.

Let

Gets or sets the let document.

public BsonDocument Let { get; set; }

Property Value

BsonDocument

The let document.

Limit

Gets or sets the limit.

public int? Limit { get; set; }

Property Value

int?

The limit.

Max

Gets or sets the max key value.

public BsonDocument Max { get; set; }

Property Value

BsonDocument

The max key value.

MaxAwaitTime

Gets or sets the maximum await time for TailableAwait cursors.

public TimeSpan? MaxAwaitTime { get; set; }

Property Value

TimeSpan?

The maximum await time for TailableAwait cursors.

MaxScan

Gets or sets the max scan.

[Obsolete("MaxScan was deprecated in server version 4.0.")]
public int? MaxScan { get; set; }

Property Value

int?

The max scan.

MaxTime

Gets or sets the maximum time the server should spend on this operation.

public TimeSpan? MaxTime { get; set; }

Property Value

TimeSpan?

The maximum time the server should spend on this operation.

MessageEncoderSettings

Gets the message encoder settings.

public MessageEncoderSettings MessageEncoderSettings { get; }

Property Value

MessageEncoderSettings

The message encoder settings.

Min

Gets or sets the min key value.

public BsonDocument Min { get; set; }

Property Value

BsonDocument

The max min value.

Modifiers

Gets or sets any additional query modifiers.

[Obsolete("Use individual properties instead.")]
public BsonDocument Modifiers { get; set; }

Property Value

BsonDocument

The additional query modifiers.

NoCursorTimeout

Gets or sets a value indicating whether the server will not timeout the cursor.

public bool? NoCursorTimeout { get; set; }

Property Value

bool?

true if the server will not timeout the cursor; otherwise, false.

OplogReplay

Gets or sets a value indicating whether the OplogReplay bit will be set.

[Obsolete("OplogReplay is ignored by server versions 4.4.0 and newer.")]
public bool? OplogReplay { get; set; }

Property Value

bool?

true if the OplogReplay bit will be set; otherwise, false.

Projection

Gets or sets the projection.

public BsonDocument Projection { get; set; }

Property Value

BsonDocument

The projection.

ReadConcern

Gets or sets the read concern.

public ReadConcern ReadConcern { get; set; }

Property Value

ReadConcern

The read concern.

ResultSerializer

Gets the result serializer.

public IBsonSerializer<TDocument> ResultSerializer { get; }

Property Value

IBsonSerializer<TDocument>

The result serializer.

RetryRequested

Gets or sets a value indicating whether to retry.

public bool RetryRequested { get; set; }

Property Value

bool

Whether to retry.

ReturnKey

Gets or sets whether to only return the key values.

public bool? ReturnKey { get; set; }

Property Value

bool?

Whether to only return the key values.

ShowRecordId

Gets or sets whether the record Id should be added to the result document.

public bool? ShowRecordId { get; set; }

Property Value

bool?

Whether the record Id should be added to the result documentr.

SingleBatch

Gets or sets whether to return only a single batch.

public bool? SingleBatch { get; set; }

Property Value

bool?

Whether to return only a single batchThe single batch.

Skip

Gets or sets the number of documents skip.

public int? Skip { get; set; }

Property Value

int?

The number of documents skip.

Snapshot

Gets or sets whether to use snapshot behavior.

[Obsolete("Snapshot was deprecated in server version 3.7.4.")]
public bool? Snapshot { get; set; }

Property Value

bool?

Whether to use snapshot behavior.

Sort

Gets or sets the sort specification.

public BsonDocument Sort { get; set; }

Property Value

BsonDocument

The sort specification.

Methods

CreateCommand(ConnectionDescription, ICoreSession)

Creates the command to be explained.

public BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)

Parameters

connectionDescription ConnectionDescription

The connection description.

session ICoreSession

The session.

Returns

BsonDocument

The command.

Execute(IReadBinding, CancellationToken)

Executes the operation.

public IAsyncCursor<TDocument> Execute(IReadBinding binding, CancellationToken cancellationToken = default)

Parameters

binding IReadBinding

The binding.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TDocument>

The result of the operation.

Execute(RetryableReadContext, CancellationToken)

Executes the first attempt.

public IAsyncCursor<TDocument> Execute(RetryableReadContext context, CancellationToken cancellationToken = default)

Parameters

context RetryableReadContext

The context.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TDocument>

The result.

ExecuteAsync(IReadBinding, CancellationToken)

Executes the operation.

public Task<IAsyncCursor<TDocument>> ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken = default)

Parameters

binding IReadBinding

The binding.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TDocument>>

A Task whose result is the result of the operation.

ExecuteAsync(RetryableReadContext, CancellationToken)

Executes the first attempt.

public Task<IAsyncCursor<TDocument>> ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken = default)

Parameters

context RetryableReadContext

The context.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TDocument>>

The result.