Class MongoCursor<TDocument>
An object that can be enumerated to fetch the results of a query. The query is not sent to the server until you begin enumerating the results.
public class MongoCursor<TDocument> : MongoCursor, IEnumerable<TDocument>, IEnumerable
Type Parameters
TDocument
The type of the documents returned.
- Inheritance
-
MongoCursor<TDocument>
- Implements
-
IEnumerable<TDocument>
- Inherited Members
- Extension Methods
Constructors
MongoCursor(MongoCollection, IMongoQuery, ReadConcern, ReadPreference, IBsonSerializer)
Initializes a new instance of the MongoCursor<TDocument> class.
[Obsolete("Use a method that returns a cursor instead.")]
public MongoCursor(MongoCollection collection, IMongoQuery query, ReadConcern readConcern, ReadPreference readPreference, IBsonSerializer serializer)
Parameters
collection
MongoCollectionThe collection.
query
IMongoQueryThe query.
readConcern
ReadConcernThe read concern.
readPreference
ReadPreferenceThe read preference.
serializer
IBsonSerializerThe serializer.
MongoCursor(MongoCollection, IMongoQuery, ReadPreference, IBsonSerializer)
Creates a new MongoCursor. It is very unlikely that you will call this constructor. Instead, see all the Find methods in MongoCollection.
[Obsolete("Use a method that returns a cursor instead.")]
public MongoCursor(MongoCollection collection, IMongoQuery query, ReadPreference readPreference, IBsonSerializer serializer)
Parameters
collection
MongoCollectionThe collection.
query
IMongoQueryThe query.
readPreference
ReadPreferenceThe read preference.
serializer
IBsonSerializerThe serializer.
Properties
Serializer
Gets the serializer.
public virtual IBsonSerializer<TDocument> Serializer { get; }
Property Value
- IBsonSerializer<TDocument>
Methods
CreateExplainOperation(ExplainVerbosity)
Creates an explain operation for this cursor.
protected override ExplainOperation CreateExplainOperation(ExplainVerbosity verbosity)
Parameters
verbosity
ExplainVerbosityThe requested ExplainVerbosity.
Returns
- ExplainOperation
An explain operation.
GetEnumerator()
Returns an enumerator that can be used to enumerate the cursor. Normally you will use the foreach statement to enumerate the cursor (foreach will call GetEnumerator for you).
public virtual IEnumerator<TDocument> GetEnumerator()
Returns
- IEnumerator<TDocument>
An enumerator that can be used to iterate over the cursor.
IEnumerableGetEnumerator()
Gets the non-generic enumerator.
protected override IEnumerator IEnumerableGetEnumerator()
Returns
- IEnumerator
The enumerator.
SetBatchSize(int)
Sets the batch size (the number of documents returned per batch).
public virtual MongoCursor<TDocument> SetBatchSize(int batchSize)
Parameters
batchSize
intThe number of documents in each batch.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetCollation(Collation)
Sets the collation.
public virtual MongoCursor<TDocument> SetCollation(Collation collation)
Parameters
collation
CollationThe collation.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetFields(IMongoFields)
Sets the fields that will be returned from the server.
public virtual MongoCursor<TDocument> SetFields(IMongoFields fields)
Parameters
fields
IMongoFieldsThe fields that will be returned from the server.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetFields(params string[])
Sets the fields that will be returned from the server.
public virtual MongoCursor<TDocument> SetFields(params string[] fields)
Parameters
fields
string[]The fields that will be returned from the server.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetFlags(QueryFlags)
Sets the query flags.
public virtual MongoCursor<TDocument> SetFlags(QueryFlags flags)
Parameters
flags
QueryFlagsThe query flags.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetHint(BsonDocument)
Sets the index hint for the query.
public virtual MongoCursor<TDocument> SetHint(BsonDocument hint)
Parameters
hint
BsonDocumentThe index hint.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetHint(string)
Sets the index hint for the query.
public virtual MongoCursor<TDocument> SetHint(string indexName)
Parameters
indexName
stringThe name of the index.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetLimit(int)
Sets the limit on the number of documents to be returned.
public virtual MongoCursor<TDocument> SetLimit(int limit)
Parameters
limit
intThe limit on the number of documents to be returned.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetMax(BsonDocument)
Sets the max value for the index key range of documents to return (note: the max value itself is excluded from the range). Often combined with SetHint (if SetHint is not used the server will attempt to determine the matching index automatically).
public virtual MongoCursor<TDocument> SetMax(BsonDocument max)
Parameters
max
BsonDocumentThe max value.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetMaxAwaitTime(TimeSpan?)
Sets the maximum await time for tailable await cursors.
public virtual MongoCursor SetMaxAwaitTime(TimeSpan? value)
Parameters
value
TimeSpan?The value.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
SetMaxScan(int)
Sets the maximum number of documents to scan.
[Obsolete("MaxScan was deprecated in server version 4.0.")]
public virtual MongoCursor<TDocument> SetMaxScan(int maxScan)
Parameters
maxScan
intThe maximum number of documents to scan.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetMaxTime(TimeSpan)
Sets the maximum time the server should spend on this query.
public virtual MongoCursor<TDocument> SetMaxTime(TimeSpan maxTime)
Parameters
maxTime
TimeSpanThe max time.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetMin(BsonDocument)
Sets the min value for the index key range of documents to return (note: the min value itself is included in the range). Often combined with SetHint (if SetHint is not used the server will attempt to determine the matching index automatically).
public virtual MongoCursor<TDocument> SetMin(BsonDocument min)
Parameters
min
BsonDocumentThe min value.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetOption(string, BsonValue)
Sets a cursor option.
public virtual MongoCursor<TDocument> SetOption(string name, BsonValue value)
Parameters
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetOptions(BsonDocument)
Sets multiple cursor options. See also the individual Set{Option} methods, which are easier to use.
public virtual MongoCursor<TDocument> SetOptions(BsonDocument options)
Parameters
options
BsonDocumentThe options.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetReadPreference(ReadPreference)
Sets the read preference.
public virtual MongoCursor<TDocument> SetReadPreference(ReadPreference readPreference)
Parameters
readPreference
ReadPreferenceThe read preference.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetSerializer(IBsonSerializer<TDocument>)
Sets the serializer.
public virtual MongoCursor<TDocument> SetSerializer(IBsonSerializer<TDocument> serializer)
Parameters
serializer
IBsonSerializer<TDocument>The serializer.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetShowDiskLoc()
Sets the $showDiskLoc option.
public virtual MongoCursor<TDocument> SetShowDiskLoc()
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetSkip(int)
Sets the number of documents the server should skip before returning the rest of the documents.
public virtual MongoCursor<TDocument> SetSkip(int skip)
Parameters
skip
intThe number of documents to skip.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetSnapshot()
Sets the $snapshot option.
[Obsolete("Snapshot was deprecated in server version 3.7.4.")]
public virtual MongoCursor<TDocument> SetSnapshot()
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetSortOrder(IMongoSortBy)
Sets the sort order for the server to sort the documents by before returning them.
public virtual MongoCursor<TDocument> SetSortOrder(IMongoSortBy sortBy)
Parameters
sortBy
IMongoSortByThe sort order.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).
SetSortOrder(params string[])
Sets the sort order for the server to sort the documents by before returning them.
public virtual MongoCursor<TDocument> SetSortOrder(params string[] keys)
Parameters
keys
string[]The names of the fields to sort by.
Returns
- MongoCursor<TDocument>
The cursor (so you can chain method calls to it).