Class MongoCursor
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 abstract class MongoCursor : IEnumerable
- Inheritance
-
MongoCursor
- Implements
- Derived
-
MongoCursor<TDocument>
- Inherited Members
- Extension Methods
Constructors
MongoCursor(MongoCollection, IMongoQuery, ReadConcern, ReadPreference, IBsonSerializer)
Initializes a new instance of the MongoCursor class.
protected 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.
protected MongoCursor(MongoCollection collection, IMongoQuery query, ReadPreference readPreference, IBsonSerializer serializer)
Parameters
collection
MongoCollectionThe collection.
query
IMongoQueryThe query.
readPreference
ReadPreferenceThe read preference.
serializer
IBsonSerializerThe serializer.
Properties
BatchSize
Gets or sets the batch size (the number of documents returned per batch).
public virtual int BatchSize { get; set; }
Property Value
Collation
Gets the collation.
public virtual Collation Collation { get; }
Property Value
Collection
Gets the collection that is being queried.
public virtual MongoCollection Collection { get; }
Property Value
Database
Gets the database that constains the collection that is being queried.
public virtual MongoDatabase Database { get; }
Property Value
Fields
Gets or sets the fields that will be returned from the server.
public virtual IMongoFields Fields { get; set; }
Property Value
Flags
Gets or sets the query flags.
public virtual QueryFlags Flags { get; set; }
Property Value
IsFrozen
Gets whether the cursor has been frozen to prevent further changes.
public virtual bool IsFrozen { get; protected set; }
Property Value
Limit
Gets or sets the limit on the number of documents to be returned.
public virtual int Limit { get; set; }
Property Value
MaxAwaitTime
Gets or sets the maximum await time for TailableAwait cursors.
public virtual TimeSpan? MaxAwaitTime { get; set; }
Property Value
- TimeSpan?
The maximum await time for TailableAwait cursors.
Options
Gets or sets the cursor options. See also the individual Set{Option} methods, which are easier to use.
public virtual BsonDocument Options { get; set; }
Property Value
Query
Gets the query that will be sent to the server.
public virtual IMongoQuery Query { get; }
Property Value
ReadConcern
Gets the read concern.
public virtual ReadConcern ReadConcern { get; }
Property Value
ReadPreference
Gets or sets the read preference.
public virtual ReadPreference ReadPreference { get; set; }
Property Value
Serializer
Gets the serializer.
public virtual IBsonSerializer Serializer { get; }
Property Value
Server
Gets the server that the query will be sent to.
public virtual MongoServer Server { get; }
Property Value
Skip
Gets or sets the number of documents the server should skip before returning the rest of the documents.
public virtual int Skip { get; set; }
Property Value
Methods
Clone(Type)
Creates a clone of the cursor.
public virtual MongoCursor Clone(Type documentType)
Parameters
documentType
TypeThe type of the documents returned.
Returns
- MongoCursor
A clone of the cursor.
Clone(Type, IBsonSerializer)
Creates a clone of the cursor.
public virtual MongoCursor Clone(Type documentType, IBsonSerializer serializer)
Parameters
documentType
TypeThe type of the documents returned.
serializer
IBsonSerializerThe serializer to use.
Returns
- MongoCursor
A clone of the cursor.
Clone<TDocument>()
Creates a clone of the cursor.
public virtual MongoCursor<TDocument> Clone<TDocument>()
Returns
- MongoCursor<TDocument>
A clone of the cursor.
Type Parameters
TDocument
The type of the documents returned.
Clone<TDocument>(IBsonSerializer)
Creates a clone of the cursor.
public virtual MongoCursor<TDocument> Clone<TDocument>(IBsonSerializer serializer)
Parameters
serializer
IBsonSerializerThe serializer to use.
Returns
- MongoCursor<TDocument>
A clone of the cursor.
Type Parameters
TDocument
The type of the documents returned.
Count()
Returns the number of documents that match the query (ignores Skip and Limit, unlike Size which honors them).
public virtual long Count()
Returns
- long
The number of documents that match the query.
Create(Type, MongoCollection, IMongoQuery, ReadConcern, ReadPreference, IBsonSerializer)
Creates a cursor.
[Obsolete("Use a method that returns a cursor instead.")]
public static MongoCursor Create(Type documentType, MongoCollection collection, IMongoQuery query, ReadConcern readConcern, ReadPreference readPreference, IBsonSerializer serializer)
Parameters
documentType
TypeType of the document.
collection
MongoCollectionThe collection.
query
IMongoQueryThe query.
readConcern
ReadConcernThe read concern.
readPreference
ReadPreferenceThe read preference.
serializer
IBsonSerializerThe serializer.
Returns
- MongoCursor
A cursor.
Create(Type, MongoCollection, IMongoQuery, ReadPreference, IBsonSerializer)
Creates a cursor.
[Obsolete("Use a method that returns a cursor instead.")]
public static MongoCursor Create(Type documentType, MongoCollection collection, IMongoQuery query, ReadPreference readPreference, IBsonSerializer serializer)
Parameters
documentType
TypeThe type of the returned documents.
collection
MongoCollectionThe collection to query.
query
IMongoQueryA query.
readPreference
ReadPreferenceThe read preference.
serializer
IBsonSerializerThe serializer.
Returns
- MongoCursor
A cursor.
CreateExplainOperation(ExplainVerbosity)
Creates an explain operation for this cursor.
protected abstract ExplainOperation CreateExplainOperation(ExplainVerbosity verbosity)
Parameters
verbosity
ExplainVerbosityThe requested ExplainVerbosity.
Returns
- ExplainOperation
An explain operation.
Explain()
Returns an explanation of how the query was executed (instead of the results).
public virtual BsonDocument Explain()
Returns
- BsonDocument
An explanation of thow the query was executed.
Explain(bool)
Returns an explanation of how the query was executed (instead of the results).
public virtual BsonDocument Explain(bool verbose)
Parameters
verbose
boolWhether the explanation should contain more details.
Returns
- BsonDocument
An explanation of throw the query was executed.
IEnumerableGetEnumerator()
Gets the non-generic enumerator.
protected abstract IEnumerator IEnumerableGetEnumerator()
Returns
- IEnumerator
The enumerator.
SetBatchSize(int)
Sets the batch size (the number of documents returned per batch).
public virtual MongoCursor SetBatchSize(int batchSize)
Parameters
batchSize
intThe number of documents in each batch.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
SetCollation(Collation)
Sets the collation.
public virtual MongoCursor SetCollation(Collation collation)
Parameters
collation
CollationThe collation.
Returns
- MongoCursor
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 SetFields(IMongoFields fields)
Parameters
fields
IMongoFieldsThe fields that will be returned from the server.
Returns
- MongoCursor
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 SetFields(params string[] fields)
Parameters
fields
string[]The fields that will be returned from the server.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
SetFlags(QueryFlags)
Sets the query flags.
public virtual MongoCursor SetFlags(QueryFlags flags)
Parameters
flags
QueryFlagsThe query flags.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
SetHint(BsonDocument)
Sets the index hint for the query.
public virtual MongoCursor SetHint(BsonDocument hint)
Parameters
hint
BsonDocumentThe index hint.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
SetHint(string)
Sets the index hint for the query.
public virtual MongoCursor SetHint(string indexName)
Parameters
indexName
stringThe name of the index.
Returns
- MongoCursor
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 SetLimit(int limit)
Parameters
limit
intThe limit on the number of documents to be returned.
Returns
- MongoCursor
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 SetMax(BsonDocument max)
Parameters
max
BsonDocumentThe max value.
Returns
- MongoCursor
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 SetMaxScan(int maxScan)
Parameters
maxScan
intThe maximum number of documents to scan.
Returns
- MongoCursor
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 SetMaxTime(TimeSpan maxTime)
Parameters
maxTime
TimeSpanThe max time.
Returns
- MongoCursor
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 SetMin(BsonDocument min)
Parameters
min
BsonDocumentThe min value.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
SetOption(string, BsonValue)
Sets a cursor option.
public virtual MongoCursor SetOption(string name, BsonValue value)
Parameters
Returns
- MongoCursor
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 SetOptions(BsonDocument options)
Parameters
options
BsonDocumentThe options.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
SetReadPreference(ReadPreference)
Sets the read preference.
public virtual MongoCursor SetReadPreference(ReadPreference readPreference)
Parameters
readPreference
ReadPreferenceThe read preference.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
SetSerializer(IBsonSerializer)
Sets the serializer.
public virtual MongoCursor SetSerializer(IBsonSerializer serializer)
Parameters
serializer
IBsonSerializerThe serializer.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
SetShowDiskLoc()
Sets the $showDiskLoc option.
public virtual MongoCursor SetShowDiskLoc()
Returns
- MongoCursor
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 SetSkip(int skip)
Parameters
skip
intThe number of documents to skip.
Returns
- MongoCursor
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 SetSnapshot()
Returns
- MongoCursor
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 SetSortOrder(IMongoSortBy sortBy)
Parameters
sortBy
IMongoSortByThe sort order.
Returns
- MongoCursor
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 SetSortOrder(params string[] keys)
Parameters
keys
string[]The names of the fields to sort by.
Returns
- MongoCursor
The cursor (so you can chain method calls to it).
Size()
Returns the size of the result set (honors Skip and Limit, unlike Count which does not).
public virtual long Size()
Returns
- long
The size of the result set.