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.
- Inheritance
-
Mongo
Cursor
- Implements
- Derived
-
Mongo
Cursor <TDocument>
- Inherited Members
- Extension Methods
Constructors
MongoCursor(MongoCollection, IMongoQuery, ReadConcern, ReadPreference, IBsonSerializer)
Initializes a new instance of the Mongo
protected MongoCursor(MongoCollection collection, IMongoQuery query, ReadConcern readConcern, ReadPreference readPreference, IBsonSerializer serializer)
Parameters
collection
MongoCollection The collection.
query
IMongoQuery The query.
readConcern
ReadConcern The read concern.
readPreference
ReadPreference The read preference.
serializer
IBsonSerializer The 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
MongoCollection The collection.
query
IMongoQuery The query.
readPreference
ReadPreference The read preference.
serializer
IBsonSerializer The serializer.
Properties
BatchSize
Gets or sets the batch size (the number of documents returned per batch).
Property Value
Collation
Gets the collation.
Property Value
Collection
Gets the collection that is being queried.
Property Value
Database
Gets the database that constains the collection that is being queried.
Property Value
Fields
Gets or sets the fields that will be returned from the server.
Property Value
Flags
Gets or sets the query flags.
Property Value
IsFrozen
Gets whether the cursor has been frozen to prevent further changes.
Property Value
Limit
Gets or sets the limit on the number of documents to be returned.
Property Value
MaxAwaitTime
Gets or sets the maximum await time for TailableAwait cursors.
Property Value
- Time
Span ? 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.
Property Value
Query
Gets the query that will be sent to the server.
Property Value
ReadConcern
Gets the read concern.
Property Value
ReadPreference
Gets or sets the read preference.
Property Value
Serializer
Gets the serializer.
Property Value
Server
Gets the server that the query will be sent to.
Property Value
Skip
Gets or sets the number of documents the server should skip before returning the rest of the documents.
Property Value
Methods
Clone(Type)
Creates a clone of the cursor.
Parameters
documentType
TypeThe type of the documents returned.
Returns
- Mongo
Cursor A clone of the cursor.
Clone(Type, IBsonSerializer)
Creates a clone of the cursor.
Parameters
documentType
TypeThe type of the documents returned.
serializer
IBsonSerializer The serializer to use.
Returns
- Mongo
Cursor A clone of the cursor.
Clone<TDocument>()
Creates a clone of the cursor.
Returns
- Mongo
Cursor <TDocument> A clone of the cursor.
Type Parameters
TDocument
The type of the documents returned.
Clone<TDocument>(IBsonSerializer)
Creates a clone of the cursor.
Parameters
serializer
IBsonSerializer The serializer to use.
Returns
- Mongo
Cursor <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).
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
MongoCollection The collection.
query
IMongoQuery The query.
readConcern
ReadConcern The read concern.
readPreference
ReadPreference The read preference.
serializer
IBsonSerializer The serializer.
Returns
- Mongo
Cursor 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
MongoCollection The collection to query.
query
IMongoQuery A query.
readPreference
ReadPreference The read preference.
serializer
IBsonSerializer The serializer.
Returns
- Mongo
Cursor A cursor.
CreateExplainOperation(ExplainVerbosity)
Creates an explain operation for this cursor.
Parameters
verbosity
ExplainVerbosity The requested Explain
Verbosity .
Returns
- Explain
Operation An explain operation.
Explain()
Returns an explanation of how the query was executed (instead of the results).
Returns
- Bson
Document An explanation of thow the query was executed.
Explain(bool)
Returns an explanation of how the query was executed (instead of the results).
Parameters
verbose
boolWhether the explanation should contain more details.
Returns
- Bson
Document An explanation of throw the query was executed.
IEnumerableGetEnumerator()
Gets the non-generic enumerator.
Returns
- IEnumerator
The enumerator.
SetBatchSize(int)
Sets the batch size (the number of documents returned per batch).
Parameters
batchSize
intThe number of documents in each batch.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetCollation(Collation)
Sets the collation.
Parameters
collation
CollationThe collation.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetFields(IMongoFields)
Sets the fields that will be returned from the server.
Parameters
fields
IMongoFields The fields that will be returned from the server.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetFields(params string[])
Sets the fields that will be returned from the server.
Parameters
fields
string[]The fields that will be returned from the server.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetFlags(QueryFlags)
Sets the query flags.
Parameters
flags
QueryFlags The query flags.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetHint(BsonDocument)
Sets the index hint for the query.
Parameters
hint
BsonDocument The index hint.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetHint(string)
Sets the index hint for the query.
Parameters
indexName
stringThe name of the index.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetLimit(int)
Sets the limit on the number of documents to be returned.
Parameters
limit
intThe limit on the number of documents to be returned.
Returns
- Mongo
Cursor 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).
Parameters
max
BsonDocument The max value.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetMaxAwaitTime(TimeSpan?)
Sets the maximum await time for tailable await cursors.
Parameters
value
TimeSpan ?The value.
Returns
- Mongo
Cursor 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
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetMaxTime(TimeSpan)
Sets the maximum time the server should spend on this query.
Parameters
maxTime
TimeSpan The max time.
Returns
- Mongo
Cursor 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).
Parameters
min
BsonDocument The min value.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetOption(string, BsonValue)
Sets a cursor option.
Parameters
Returns
- Mongo
Cursor 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.
Parameters
options
BsonDocument The options.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetReadPreference(ReadPreference)
Sets the read preference.
Parameters
readPreference
ReadPreference The read preference.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetSerializer(IBsonSerializer)
Sets the serializer.
Parameters
serializer
IBsonSerializer The serializer.
Returns
- Mongo
Cursor The cursor (so you can chain method calls to it).
SetShowDiskLoc()
Sets the $showDiskLoc option.
Returns
- Mongo
Cursor 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.
Parameters
skip
intThe number of documents to skip.
Returns
- Mongo
Cursor 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
- Mongo
Cursor 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.
Parameters
sortBy
IMongoSort By The sort order.
Returns
- Mongo
Cursor 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.
Parameters
keys
string[]The names of the fields to sort by.
Returns
- Mongo
Cursor 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).
Returns
- long
The size of the result set.