Table of Contents

Class MongoCollection

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.Legacy.dll

Represents a MongoDB collection and the settings used to access it. This class is thread-safe.

public abstract class MongoCollection
Inheritance
MongoCollection
Derived
Inherited Members
Extension Methods

Constructors

MongoCollection(MongoDatabase, string, MongoCollectionSettings)

Protected constructor for abstract base class.

protected MongoCollection(MongoDatabase database, string name, MongoCollectionSettings settings)

Parameters

database MongoDatabase

The database that contains this collection.

name string

The name of the collection.

settings MongoCollectionSettings

The settings to use to access this collection.

Properties

Database

Gets the database that contains this collection.

public virtual MongoDatabase Database { get; }

Property Value

MongoDatabase

FullName

Gets the fully qualified name of this collection.

public virtual string FullName { get; }

Property Value

string

Name

Gets the name of this collection.

public virtual string Name { get; }

Property Value

string

Settings

Gets the settings being used to access this collection.

public virtual MongoCollectionSettings Settings { get; }

Property Value

MongoCollectionSettings

Methods

Aggregate(AggregateArgs)

Represents an aggregate framework query. The command is not sent to the server until the result is enumerated.

public virtual IEnumerable<BsonDocument> Aggregate(AggregateArgs args)

Parameters

args AggregateArgs

The args.

Returns

IEnumerable<BsonDocument>

A sequence of documents.

AggregateExplain(AggregateArgs)

Runs an aggregate command with explain set and returns the explain result.

public virtual CommandResult AggregateExplain(AggregateArgs args)

Parameters

args AggregateArgs

The args.

Returns

CommandResult

The explain result.

Count()

Counts the number of documents in this collection.

public virtual long Count()

Returns

long

The number of documents in this collection.

Count(CountArgs)

Counts the number of documents in this collection that match a query.

public virtual long Count(CountArgs args)

Parameters

args CountArgs

The args.

Returns

long

The number of documents in this collection that match the query.

Count(IMongoQuery)

Counts the number of documents in this collection that match a query.

public virtual long Count(IMongoQuery query)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

Returns

long

The number of documents in this collection that match the query.

CreateIndex(IMongoIndexKeys)

Creates an index for this collection.

public virtual WriteConcernResult CreateIndex(IMongoIndexKeys keys)

Parameters

keys IMongoIndexKeys

The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).

Returns

WriteConcernResult

A WriteConcernResult.

CreateIndex(IMongoIndexKeys, IMongoIndexOptions)

Creates an index for this collection.

public virtual WriteConcernResult CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options)

Parameters

keys IMongoIndexKeys

The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).

options IMongoIndexOptions

The index options(usually an IndexOptionsDocument or created using the IndexOption builder).

Returns

WriteConcernResult

A WriteConcernResult.

CreateIndex(params string[])

Creates an index for this collection.

public virtual WriteConcernResult CreateIndex(params string[] keyNames)

Parameters

keyNames string[]

The names of the indexed fields.

Returns

WriteConcernResult

A WriteConcernResult.

Distinct(string)

Returns the distinct values for a given field.

public virtual IEnumerable<BsonValue> Distinct(string key)

Parameters

key string

The key of the field.

Returns

IEnumerable<BsonValue>

The distint values of the field.

Distinct(string, IMongoQuery)

Returns the distinct values for a given field for documents that match a query.

public virtual IEnumerable<BsonValue> Distinct(string key, IMongoQuery query)

Parameters

key string

The key of the field.

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

Returns

IEnumerable<BsonValue>

The distint values of the field.

Distinct<TValue>(DistinctArgs)

Returns the distinct values for a given field.

public IEnumerable<TValue> Distinct<TValue>(DistinctArgs args)

Parameters

args DistinctArgs

The args.

Returns

IEnumerable<TValue>

The distint values of the field.

Type Parameters

TValue

The type of the value.

Distinct<TValue>(string)

Returns the distinct values for a given field.

public virtual IEnumerable<TValue> Distinct<TValue>(string key)

Parameters

key string

The key of the field.

Returns

IEnumerable<TValue>

The distint values of the field.

Type Parameters

TValue

The type of the value.

Distinct<TValue>(string, IMongoQuery)

Returns the distinct values for a given field for documents that match a query.

public virtual IEnumerable<TValue> Distinct<TValue>(string key, IMongoQuery query)

Parameters

key string

The key of the field.

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

Returns

IEnumerable<TValue>

The distint values of the field.

Type Parameters

TValue

The type of the value.

Drop()

Drops this collection.

public virtual CommandResult Drop()

Returns

CommandResult

A CommandResult.

DropAllIndexes()

Drops all indexes on this collection.

public virtual CommandResult DropAllIndexes()

Returns

CommandResult

A CommandResult.

DropIndex(IMongoIndexKeys)

Drops an index on this collection.

public virtual CommandResult DropIndex(IMongoIndexKeys keys)

Parameters

keys IMongoIndexKeys

The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).

Returns

CommandResult

A CommandResult.

DropIndex(params string[])

Drops an index on this collection.

public virtual CommandResult DropIndex(params string[] keyNames)

Parameters

keyNames string[]

The names of the indexed fields.

Returns

CommandResult

A CommandResult.

DropIndexByName(string)

Drops an index on this collection.

public virtual CommandResult DropIndexByName(string indexName)

Parameters

indexName string

The name of the index.

Returns

CommandResult

A CommandResult.

EnsureIndex(IMongoIndexKeys)

Ensures that the desired index exists and creates it if it does not.

[Obsolete("Use CreateIndex instead.")]
public virtual void EnsureIndex(IMongoIndexKeys keys)

Parameters

keys IMongoIndexKeys

The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).

EnsureIndex(IMongoIndexKeys, IMongoIndexOptions)

Ensures that the desired index exists and creates it if it does not.

[Obsolete("Use CreateIndex instead.")]
public virtual void EnsureIndex(IMongoIndexKeys keys, IMongoIndexOptions options)

Parameters

keys IMongoIndexKeys

The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).

options IMongoIndexOptions

The index options(usually an IndexOptionsDocument or created using the IndexOption builder).

EnsureIndex(params string[])

Ensures that the desired index exists and creates it if it does not.

[Obsolete("Use CreateIndex instead.")]
public virtual void EnsureIndex(params string[] keyNames)

Parameters

keyNames string[]

The names of the indexed fields.

Exists()

Tests whether this collection exists.

public virtual bool Exists()

Returns

bool

True if this collection exists.

FindAllAs(Type)

Returns a cursor that can be used to find all documents in this collection as TDocuments.

public virtual MongoCursor FindAllAs(Type documentType)

Parameters

documentType Type

The nominal type of the documents.

Returns

MongoCursor

A MongoCursor<TDocument>.

FindAllAs<TDocument>()

Returns a cursor that can be used to find all documents in this collection as TDocuments.

public virtual MongoCursor<TDocument> FindAllAs<TDocument>()

Returns

MongoCursor<TDocument>

A MongoCursor<TDocument>.

Type Parameters

TDocument

The nominal type of the documents.

FindAndModify(FindAndModifyArgs)

Finds one matching document using the supplied arguments and applies the specified update to it.

public virtual FindAndModifyResult FindAndModify(FindAndModifyArgs args)

Parameters

args FindAndModifyArgs

The args.

Returns

FindAndModifyResult

A FindAndModifyResult.

FindAndModify(IMongoQuery, IMongoSortBy, IMongoUpdate)

Finds one matching document using the query and sortBy parameters and applies the specified update to it.

[Obsolete("Use the overload of FindAndModify that has a FindAndModifyArgs parameter instead.")]
public virtual FindAndModifyResult FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

sortBy IMongoSortBy

The sort order to select one of the matching documents.

update IMongoUpdate

The update to apply to the matching document.

Returns

FindAndModifyResult

A FindAndModifyResult.

FindAndModify(IMongoQuery, IMongoSortBy, IMongoUpdate, IMongoFields, bool, bool)

Finds one matching document using the query and sortBy parameters and applies the specified update to it.

[Obsolete("Use the overload of FindAndModify that has a FindAndModifyArgs parameter instead.")]
public virtual FindAndModifyResult FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update, IMongoFields fields, bool returnNew, bool upsert)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

sortBy IMongoSortBy

The sort order to select one of the matching documents.

update IMongoUpdate

The update to apply to the matching document.

fields IMongoFields

Which fields of the modified document to return in the FindAndModifyResult.

returnNew bool

Whether to return the new or old version of the modified document in the FindAndModifyResult.

upsert bool

Whether to do an upsert if no matching document is found.

Returns

FindAndModifyResult

A FindAndModifyResult.

FindAndModify(IMongoQuery, IMongoSortBy, IMongoUpdate, bool)

Finds one matching document using the query and sortBy parameters and applies the specified update to it.

[Obsolete("Use the overload of FindAndModify that has a FindAndModifyArgs parameter instead.")]
public virtual FindAndModifyResult FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update, bool returnNew)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

sortBy IMongoSortBy

The sort order to select one of the matching documents.

update IMongoUpdate

The update to apply to the matching document.

returnNew bool

Whether to return the new or old version of the modified document in the FindAndModifyResult.

Returns

FindAndModifyResult

A FindAndModifyResult.

FindAndModify(IMongoQuery, IMongoSortBy, IMongoUpdate, bool, bool)

Finds one matching document using the query and sortBy parameters and applies the specified update to it.

[Obsolete("Use the overload of FindAndModify that has a FindAndModifyArgs parameter instead.")]
public virtual FindAndModifyResult FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update, bool returnNew, bool upsert)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

sortBy IMongoSortBy

The sort order to select one of the matching documents.

update IMongoUpdate

The update to apply to the matching document.

returnNew bool

Whether to return the new or old version of the modified document in the FindAndModifyResult.

upsert bool

Whether to do an upsert if no matching document is found.

Returns

FindAndModifyResult

A FindAndModifyResult.

FindAndRemove(FindAndRemoveArgs)

Finds one matching document using the supplied args and removes it from this collection.

public virtual FindAndModifyResult FindAndRemove(FindAndRemoveArgs args)

Parameters

args FindAndRemoveArgs

The args.

Returns

FindAndModifyResult

A FindAndModifyResult.

FindAndRemove(IMongoQuery, IMongoSortBy)

Finds one matching document using the query and sortBy parameters and removes it from this collection.

[Obsolete("Use the overload of FindAndRemove that has a FindAndRemoveArgs parameter instead.")]
public virtual FindAndModifyResult FindAndRemove(IMongoQuery query, IMongoSortBy sortBy)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

sortBy IMongoSortBy

The sort order to select one of the matching documents.

Returns

FindAndModifyResult

A FindAndModifyResult.

FindAs(Type, IMongoQuery)

Returns a cursor that can be used to find all documents in this collection that match the query as TDocuments.

public virtual MongoCursor FindAs(Type documentType, IMongoQuery query)

Parameters

documentType Type

The nominal type of the documents.

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

Returns

MongoCursor

A MongoCursor<TDocument>.

FindAs<TDocument>(IMongoQuery)

Returns a cursor that can be used to find all documents in this collection that match the query as TDocuments.

public virtual MongoCursor<TDocument> FindAs<TDocument>(IMongoQuery query)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

Returns

MongoCursor<TDocument>

A MongoCursor<TDocument>.

Type Parameters

TDocument

The type to deserialize the documents as.

FindOneAs(Type)

Returns one document in this collection as a TDocument.

public virtual object FindOneAs(Type documentType)

Parameters

documentType Type

The nominal type of the documents.

Returns

object

A document (or null if not found).

FindOneAs(Type, FindOneArgs)

Returns one document in this collection as a TDocument.

public virtual object FindOneAs(Type documentType, FindOneArgs args)

Parameters

documentType Type

The nominal type of the documents.

args FindOneArgs

The args.

Returns

object

A document (or null if not found).

FindOneAs(Type, IMongoQuery)

Returns one document in this collection that matches a query as a TDocument.

public virtual object FindOneAs(Type documentType, IMongoQuery query)

Parameters

documentType Type

The type to deserialize the documents as.

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

Returns

object

A TDocument (or null if not found).

FindOneAs<TDocument>()

Returns one document in this collection as a TDocument.

public virtual TDocument FindOneAs<TDocument>()

Returns

TDocument

A TDocument (or null if not found).

Type Parameters

TDocument

The type to deserialize the documents as.

FindOneAs<TDocument>(FindOneArgs)

Returns one document in this collection as a TDocument.

public virtual TDocument FindOneAs<TDocument>(FindOneArgs args)

Parameters

args FindOneArgs

The args.

Returns

TDocument

A TDocument (or null if not found).

Type Parameters

TDocument

The type of the document.

FindOneAs<TDocument>(IMongoQuery)

Returns one document in this collection that matches a query as a TDocument.

public virtual TDocument FindOneAs<TDocument>(IMongoQuery query)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

Returns

TDocument

A TDocument (or null if not found).

Type Parameters

TDocument

The type to deserialize the documents as.

FindOneByIdAs(Type, BsonValue)

Returns a cursor that can be used to find one document in this collection by its _id value as a TDocument.

public virtual object FindOneByIdAs(Type documentType, BsonValue id)

Parameters

documentType Type

The nominal type of the document.

id BsonValue

The id of the document.

Returns

object

A TDocument (or null if not found).

FindOneByIdAs<TDocument>(BsonValue)

Returns a cursor that can be used to find one document in this collection by its _id value as a TDocument.

public virtual TDocument FindOneByIdAs<TDocument>(BsonValue id)

Parameters

id BsonValue

The id of the document.

Returns

TDocument

A TDocument (or null if not found).

Type Parameters

TDocument

The nominal type of the document.

GeoHaystackSearchAs(Type, GeoHaystackSearchArgs)

Runs a geoHaystack search command on this collection.

[Obsolete("GeoHaystack indexes were deprecated in server version 4.4.")]
public virtual GeoHaystackSearchResult GeoHaystackSearchAs(Type documentType, GeoHaystackSearchArgs args)

Parameters

documentType Type

The type to deserialize the documents as.

args GeoHaystackSearchArgs

The args.

Returns

GeoHaystackSearchResult

A GeoNearResult<TDocument>.

GeoHaystackSearchAs(Type, double, double, IMongoGeoHaystackSearchOptions)

Runs a geoHaystack search command on this collection.

[Obsolete("Use the overload of GeoHaystackSearchAs that has a GeoHaystackSearchArgs parameter instead.")]
public virtual GeoHaystackSearchResult GeoHaystackSearchAs(Type documentType, double x, double y, IMongoGeoHaystackSearchOptions options)

Parameters

documentType Type

The type to deserialize the documents as.

x double

The x coordinate of the starting location.

y double

The y coordinate of the starting location.

options IMongoGeoHaystackSearchOptions

The options for the geoHaystack search (null if none).

Returns

GeoHaystackSearchResult

A GeoNearResult<TDocument>.

GeoHaystackSearchAs<TDocument>(GeoHaystackSearchArgs)

Runs a geoHaystack search command on this collection.

[Obsolete("GeoHaystack indexes were deprecated in server version 4.4.")]
public virtual GeoHaystackSearchResult<TDocument> GeoHaystackSearchAs<TDocument>(GeoHaystackSearchArgs args)

Parameters

args GeoHaystackSearchArgs

The args.

Returns

GeoHaystackSearchResult<TDocument>

A GeoNearResult<TDocument>.

Type Parameters

TDocument

The type of the found documents.

GeoHaystackSearchAs<TDocument>(double, double, IMongoGeoHaystackSearchOptions)

Runs a geoHaystack search command on this collection.

[Obsolete("Use the overload of GeoHaystackSearchAs that has a GeoHaystackSearchArgs parameter instead.")]
public virtual GeoHaystackSearchResult<TDocument> GeoHaystackSearchAs<TDocument>(double x, double y, IMongoGeoHaystackSearchOptions options)

Parameters

x double

The x coordinate of the starting location.

y double

The y coordinate of the starting location.

options IMongoGeoHaystackSearchOptions

The options for the geoHaystack search (null if none).

Returns

GeoHaystackSearchResult<TDocument>

A GeoNearResult<TDocument>.

Type Parameters

TDocument

The type of the found documents.

GeoNearAs(Type, GeoNearArgs)

Runs a GeoNear command on this collection.

public virtual GeoNearResult GeoNearAs(Type documentType, GeoNearArgs args)

Parameters

documentType Type

The type to deserialize the documents as.

args GeoNearArgs

The args.

Returns

GeoNearResult

A GeoNearResult<TDocument>.

GeoNearAs(Type, IMongoQuery, double, double, int)

Runs a GeoNear command on this collection.

[Obsolete("Use the overload of GeoNearAs that has a GeoNearArgs parameter instead.")]
public virtual GeoNearResult GeoNearAs(Type documentType, IMongoQuery query, double x, double y, int limit)

Parameters

documentType Type

The type to deserialize the documents as.

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

x double

The x coordinate of the starting location.

y double

The y coordinate of the starting location.

limit int

The maximum number of results returned.

Returns

GeoNearResult

A GeoNearResult<TDocument>.

GeoNearAs(Type, IMongoQuery, double, double, int, IMongoGeoNearOptions)

Runs a GeoNear command on this collection.

[Obsolete("Use the overload of GeoNearAs that has a GeoNearArgs parameter instead.")]
public virtual GeoNearResult GeoNearAs(Type documentType, IMongoQuery query, double x, double y, int limit, IMongoGeoNearOptions options)

Parameters

documentType Type

The type to deserialize the documents as.

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

x double

The x coordinate of the starting location.

y double

The y coordinate of the starting location.

limit int

The maximum number of results returned.

options IMongoGeoNearOptions

The GeoNear command options (usually a GeoNearOptionsDocument or constructed using the GeoNearOptions builder).

Returns

GeoNearResult

A GeoNearResult<TDocument>.

GeoNearAs<TDocument>(GeoNearArgs)

Runs a GeoNear command on this collection.

public virtual GeoNearResult<TDocument> GeoNearAs<TDocument>(GeoNearArgs args)

Parameters

args GeoNearArgs

The args.

Returns

GeoNearResult<TDocument>

A GeoNearResult<TDocument>.

Type Parameters

TDocument

The type to deserialize the documents as.

GeoNearAs<TDocument>(IMongoQuery, double, double, int)

Runs a GeoNear command on this collection.

[Obsolete("Use the overload of GeoNearAs that has a GeoNearArgs parameter instead.")]
public virtual GeoNearResult<TDocument> GeoNearAs<TDocument>(IMongoQuery query, double x, double y, int limit)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

x double

The x coordinate of the starting location.

y double

The y coordinate of the starting location.

limit int

The maximum number of results returned.

Returns

GeoNearResult<TDocument>

A GeoNearResult<TDocument>.

Type Parameters

TDocument

The type to deserialize the documents as.

GeoNearAs<TDocument>(IMongoQuery, double, double, int, IMongoGeoNearOptions)

Runs a GeoNear command on this collection.

[Obsolete("Use the overload of GeoNearAs that has a GeoNearArgs parameter instead.")]
public virtual GeoNearResult<TDocument> GeoNearAs<TDocument>(IMongoQuery query, double x, double y, int limit, IMongoGeoNearOptions options)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

x double

The x coordinate of the starting location.

y double

The y coordinate of the starting location.

limit int

The maximum number of results returned.

options IMongoGeoNearOptions

The GeoNear command options (usually a GeoNearOptionsDocument or constructed using the GeoNearOptions builder).

Returns

GeoNearResult<TDocument>

A GeoNearResult<TDocument>.

Type Parameters

TDocument

The type to deserialize the documents as.

GetIndexes()

Gets the indexes for this collection.

public virtual GetIndexesResult GetIndexes()

Returns

GetIndexesResult

A list of BsonDocuments that describe the indexes.

GetStats()

Gets the stats for this collection.

public virtual CollectionStatsResult GetStats()

Returns

CollectionStatsResult

The stats for this collection as a CollectionStatsResult.

GetStats(GetStatsArgs)

Gets the stats for this collection.

public virtual CollectionStatsResult GetStats(GetStatsArgs args)

Parameters

args GetStatsArgs

The args.

Returns

CollectionStatsResult

The stats for this collection as a CollectionStatsResult.

Group(GroupArgs)

Runs the group command on this collection.

[Obsolete("The group command was deprecated in server version 3.4.")]
public virtual IEnumerable<BsonDocument> Group(GroupArgs args)

Parameters

args GroupArgs

The args.

Returns

IEnumerable<BsonDocument>

A list of results as BsonDocuments.

Group(IMongoQuery, BsonJavaScript, BsonDocument, BsonJavaScript, BsonJavaScript)

Runs the group command on this collection.

[Obsolete("The group command was deprecated in server version 3.4.")]
public virtual IEnumerable<BsonDocument> Group(IMongoQuery query, BsonJavaScript keyFunction, BsonDocument initial, BsonJavaScript reduce, BsonJavaScript finalize)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

keyFunction BsonJavaScript

A JavaScript function that returns the key value to group on.

initial BsonDocument

Initial value passed to the reduce function for each group.

reduce BsonJavaScript

A JavaScript function that is called for each matching document in a group.

finalize BsonJavaScript

A JavaScript function that is called at the end of the group command.

Returns

IEnumerable<BsonDocument>

A list of results as BsonDocuments.

Group(IMongoQuery, IMongoGroupBy, BsonDocument, BsonJavaScript, BsonJavaScript)

Runs the group command on this collection.

[Obsolete("The group command was deprecated in server version 3.4.")]
public virtual IEnumerable<BsonDocument> Group(IMongoQuery query, IMongoGroupBy keys, BsonDocument initial, BsonJavaScript reduce, BsonJavaScript finalize)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

keys IMongoGroupBy

The names of the fields to group on.

initial BsonDocument

Initial value passed to the reduce function for each group.

reduce BsonJavaScript

A JavaScript function that is called for each matching document in a group.

finalize BsonJavaScript

A JavaScript function that is called at the end of the group command.

Returns

IEnumerable<BsonDocument>

A list of results as BsonDocuments.

Group(IMongoQuery, string, BsonDocument, BsonJavaScript, BsonJavaScript)

Runs the group command on this collection.

[Obsolete("The group command was deprecated in server version 3.4.")]
public virtual IEnumerable<BsonDocument> Group(IMongoQuery query, string key, BsonDocument initial, BsonJavaScript reduce, BsonJavaScript finalize)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

key string

The name of the field to group on.

initial BsonDocument

Initial value passed to the reduce function for each group.

reduce BsonJavaScript

A JavaScript function that is called for each matching document in a group.

finalize BsonJavaScript

A JavaScript function that is called at the end of the group command.

Returns

IEnumerable<BsonDocument>

A list of results as BsonDocuments.

IndexExists(IMongoIndexKeys)

Tests whether an index exists.

public virtual bool IndexExists(IMongoIndexKeys keys)

Parameters

keys IMongoIndexKeys

The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).

Returns

bool

True if the index exists.

IndexExists(params string[])

Tests whether an index exists.

public virtual bool IndexExists(params string[] keyNames)

Parameters

keyNames string[]

The names of the fields in the index.

Returns

bool

True if the index exists.

IndexExistsByName(string)

Tests whether an index exists.

public virtual bool IndexExistsByName(string indexName)

Parameters

indexName string

The name of the index.

Returns

bool

True if the index exists.

InitializeOrderedBulkOperationAs<TDocument>()

Creates a fluent builder for an ordered bulk operation.

public virtual BulkWriteOperation<TDocument> InitializeOrderedBulkOperationAs<TDocument>()

Returns

BulkWriteOperation<TDocument>

A fluent bulk operation builder.

Type Parameters

TDocument

The type of the documents.

InitializeUnorderedBulkOperationAs<TDocument>()

Creates a fluent builder for an unordered bulk operation.

public virtual BulkWriteOperation<TDocument> InitializeUnorderedBulkOperationAs<TDocument>()

Returns

BulkWriteOperation<TDocument>

A fluent bulk operation builder.

Type Parameters

TDocument

The type of the documents.

Insert(Type, object)

Inserts a document into this collection (see also InsertBatch to insert multiple documents at once).

public virtual WriteConcernResult Insert(Type nominalType, object document)

Parameters

nominalType Type

The nominal type of the document to insert.

document object

The document to insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Insert(Type, object, MongoInsertOptions)

Inserts a document into this collection (see also InsertBatch to insert multiple documents at once).

public virtual WriteConcernResult Insert(Type nominalType, object document, MongoInsertOptions options)

Parameters

nominalType Type

The nominal type of the document to insert.

document object

The document to insert.

options MongoInsertOptions

The options to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Insert(Type, object, WriteConcern)

Inserts a document into this collection (see also InsertBatch to insert multiple documents at once).

public virtual WriteConcernResult Insert(Type nominalType, object document, WriteConcern writeConcern)

Parameters

nominalType Type

The nominal type of the document to insert.

document object

The document to insert.

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

InsertBatch(Type, IEnumerable)

Inserts multiple documents at once into this collection (see also Insert to insert a single document).

public virtual IEnumerable<WriteConcernResult> InsertBatch(Type nominalType, IEnumerable documents)

Parameters

nominalType Type

The nominal type of the documents to insert.

documents IEnumerable

The documents to insert.

Returns

IEnumerable<WriteConcernResult>

A list of WriteConcernResults (or null if WriteConcern is disabled).

InsertBatch(Type, IEnumerable, MongoInsertOptions)

Inserts multiple documents at once into this collection (see also Insert to insert a single document).

public virtual IEnumerable<WriteConcernResult> InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options)

Parameters

nominalType Type

The nominal type of the documents to insert.

documents IEnumerable

The documents to insert.

options MongoInsertOptions

The options to use for this Insert.

Returns

IEnumerable<WriteConcernResult>

A list of WriteConcernResults (or null if WriteConcern is disabled).

InsertBatch(Type, IEnumerable, WriteConcern)

Inserts multiple documents at once into this collection (see also Insert to insert a single document).

public virtual IEnumerable<WriteConcernResult> InsertBatch(Type nominalType, IEnumerable documents, WriteConcern writeConcern)

Parameters

nominalType Type

The nominal type of the documents to insert.

documents IEnumerable

The documents to insert.

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

IEnumerable<WriteConcernResult>

A list of WriteConcernResults (or null if WriteConcern is disabled).

InsertBatch<TNominalType>(IEnumerable<TNominalType>)

Inserts multiple documents at once into this collection (see also Insert to insert a single document).

public virtual IEnumerable<WriteConcernResult> InsertBatch<TNominalType>(IEnumerable<TNominalType> documents)

Parameters

documents IEnumerable<TNominalType>

The documents to insert.

Returns

IEnumerable<WriteConcernResult>

A list of WriteConcernResults (or null if WriteConcern is disabled).

Type Parameters

TNominalType

The type of the documents to insert.

InsertBatch<TNominalType>(IEnumerable<TNominalType>, MongoInsertOptions)

Inserts multiple documents at once into this collection (see also Insert to insert a single document).

public virtual IEnumerable<WriteConcernResult> InsertBatch<TNominalType>(IEnumerable<TNominalType> documents, MongoInsertOptions options)

Parameters

documents IEnumerable<TNominalType>

The documents to insert.

options MongoInsertOptions

The options to use for this Insert.

Returns

IEnumerable<WriteConcernResult>

A list of WriteConcernResults (or null if WriteConcern is disabled).

Type Parameters

TNominalType

The type of the documents to insert.

InsertBatch<TNominalType>(IEnumerable<TNominalType>, WriteConcern)

Inserts multiple documents at once into this collection (see also Insert to insert a single document).

public virtual IEnumerable<WriteConcernResult> InsertBatch<TNominalType>(IEnumerable<TNominalType> documents, WriteConcern writeConcern)

Parameters

documents IEnumerable<TNominalType>

The documents to insert.

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

IEnumerable<WriteConcernResult>

A list of WriteConcernResults (or null if WriteConcern is disabled).

Type Parameters

TNominalType

The type of the documents to insert.

Insert<TNominalType>(TNominalType)

Inserts a document into this collection (see also InsertBatch to insert multiple documents at once).

public virtual WriteConcernResult Insert<TNominalType>(TNominalType document)

Parameters

document TNominalType

The document to insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Type Parameters

TNominalType

The nominal type of the document to insert.

Insert<TNominalType>(TNominalType, MongoInsertOptions)

Inserts a document into this collection (see also InsertBatch to insert multiple documents at once).

public virtual WriteConcernResult Insert<TNominalType>(TNominalType document, MongoInsertOptions options)

Parameters

document TNominalType

The document to insert.

options MongoInsertOptions

The options to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Type Parameters

TNominalType

The nominal type of the document to insert.

Insert<TNominalType>(TNominalType, WriteConcern)

Inserts a document into this collection (see also InsertBatch to insert multiple documents at once).

public virtual WriteConcernResult Insert<TNominalType>(TNominalType document, WriteConcern writeConcern)

Parameters

document TNominalType

The document to insert.

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Type Parameters

TNominalType

The nominal type of the document to insert.

IsCapped()

Tests whether this collection is capped.

public virtual bool IsCapped()

Returns

bool

True if this collection is capped.

MapReduce(MapReduceArgs)

Runs a map-reduce command on this collection.

[Obsolete("Use Aggregation pipeline instead.")]
public virtual MapReduceResult MapReduce(MapReduceArgs args)

Parameters

args MapReduceArgs

The args.

Returns

MapReduceResult

A MapReduceResult.

ParallelScanAs(Type, ParallelScanArgs)

Scans an entire collection in parallel using multiple cursors.

[Obsolete("ParallelScanAs was deprecated in server version 4.1.")]
public ReadOnlyCollection<IEnumerator> ParallelScanAs(Type documentType, ParallelScanArgs args)

Parameters

documentType Type

Type of the document.

args ParallelScanArgs

The args.

Returns

ReadOnlyCollection<IEnumerator>

Multiple enumerators, one for each cursor.

ParallelScanAs<TDocument>(ParallelScanArgs<TDocument>)

Scans an entire collection in parallel using multiple cursors.

[Obsolete("ParallelScanAs was deprecated in server version 4.1.")]
public ReadOnlyCollection<IEnumerator<TDocument>> ParallelScanAs<TDocument>(ParallelScanArgs<TDocument> args)

Parameters

args ParallelScanArgs<TDocument>

The args.

Returns

ReadOnlyCollection<IEnumerator<TDocument>>

Multiple enumerators, one for each cursor.

Type Parameters

TDocument

The type of the document.

ReIndex()

Runs the ReIndex command on this collection.

[Obsolete("This method will be removed in a later version of the driver.")]
public virtual CommandResult ReIndex()

Returns

CommandResult

A CommandResult.

Remove(IMongoQuery)

Removes documents from this collection that match a query.

public virtual WriteConcernResult Remove(IMongoQuery query)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Remove(IMongoQuery, RemoveFlags)

Removes documents from this collection that match a query.

public virtual WriteConcernResult Remove(IMongoQuery query, RemoveFlags flags)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

flags RemoveFlags

The flags for this Remove (see RemoveFlags).

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Remove(IMongoQuery, RemoveFlags, WriteConcern)

Removes documents from this collection that match a query.

public virtual WriteConcernResult Remove(IMongoQuery query, RemoveFlags flags, WriteConcern writeConcern)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

flags RemoveFlags

The flags for this Remove (see RemoveFlags).

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Remove(IMongoQuery, WriteConcern)

Removes documents from this collection that match a query.

public virtual WriteConcernResult Remove(IMongoQuery query, WriteConcern writeConcern)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Remove(RemoveArgs)

Removes documents from this collection that match a query.

public virtual WriteConcernResult Remove(RemoveArgs args)

Parameters

args RemoveArgs

The arguments.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

RemoveAll()

Removes all documents from this collection (see also Drop()).

public virtual WriteConcernResult RemoveAll()

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

RemoveAll(WriteConcern)

Removes all documents from this collection (see also Drop()).

public virtual WriteConcernResult RemoveAll(WriteConcern writeConcern)

Parameters

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Save(Type, object)

Saves a document to this collection. The document must have an identifiable Id field. Based on the value of the Id field Save will perform either an Insert or an Update.

public virtual WriteConcernResult Save(Type nominalType, object document)

Parameters

nominalType Type

The type of the document to save.

document object

The document to save.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Save(Type, object, MongoInsertOptions)

Saves a document to this collection. The document must have an identifiable Id field. Based on the value of the Id field Save will perform either an Insert or an Update.

public virtual WriteConcernResult Save(Type nominalType, object document, MongoInsertOptions options)

Parameters

nominalType Type

The type of the document to save.

document object

The document to save.

options MongoInsertOptions

The options to use for this Save.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Save(Type, object, WriteConcern)

Saves a document to this collection. The document must have an identifiable Id field. Based on the value of the Id field Save will perform either an Insert or an Update.

public virtual WriteConcernResult Save(Type nominalType, object document, WriteConcern writeConcern)

Parameters

nominalType Type

The type of the document to save.

document object

The document to save.

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Save<TNominalType>(TNominalType)

Saves a document to this collection. The document must have an identifiable Id field. Based on the value of the Id field Save will perform either an Insert or an Update.

public virtual WriteConcernResult Save<TNominalType>(TNominalType document)

Parameters

document TNominalType

The document to save.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Type Parameters

TNominalType

The type of the document to save.

Save<TNominalType>(TNominalType, MongoInsertOptions)

Saves a document to this collection. The document must have an identifiable Id field. Based on the value of the Id field Save will perform either an Insert or an Update.

public virtual WriteConcernResult Save<TNominalType>(TNominalType document, MongoInsertOptions options)

Parameters

document TNominalType

The document to save.

options MongoInsertOptions

The options to use for this Save.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Type Parameters

TNominalType

The type of the document to save.

Save<TNominalType>(TNominalType, WriteConcern)

Saves a document to this collection. The document must have an identifiable Id field. Based on the value of the Id field Save will perform either an Insert or an Update.

public virtual WriteConcernResult Save<TNominalType>(TNominalType document, WriteConcern writeConcern)

Parameters

document TNominalType

The document to save.

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Type Parameters

TNominalType

The type of the document to save.

ToString()

Gets a canonical string representation for this database.

public override string ToString()

Returns

string

A canonical string representation for this database.

Update(IMongoQuery, IMongoUpdate)

Updates one matching document in this collection.

public virtual WriteConcernResult Update(IMongoQuery query, IMongoUpdate update)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

update IMongoUpdate

The update to perform on the matching document.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Update(IMongoQuery, IMongoUpdate, MongoUpdateOptions)

Updates one or more matching documents in this collection (for multiple updates use UpdateFlags.Multi).

public virtual WriteConcernResult Update(IMongoQuery query, IMongoUpdate update, MongoUpdateOptions options)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

update IMongoUpdate

The update to perform on the matching document.

options MongoUpdateOptions

The update options.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Update(IMongoQuery, IMongoUpdate, UpdateFlags)

Updates one or more matching documents in this collection (for multiple updates use UpdateFlags.Multi).

public virtual WriteConcernResult Update(IMongoQuery query, IMongoUpdate update, UpdateFlags flags)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

update IMongoUpdate

The update to perform on the matching document.

flags UpdateFlags

The flags for this Update.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Update(IMongoQuery, IMongoUpdate, UpdateFlags, WriteConcern)

Updates one or more matching documents in this collection (for multiple updates use UpdateFlags.Multi).

public virtual WriteConcernResult Update(IMongoQuery query, IMongoUpdate update, UpdateFlags flags, WriteConcern writeConcern)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

update IMongoUpdate

The update to perform on the matching document.

flags UpdateFlags

The flags for this Update.

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Update(IMongoQuery, IMongoUpdate, WriteConcern)

Updates one matching document in this collection.

public virtual WriteConcernResult Update(IMongoQuery query, IMongoUpdate update, WriteConcern writeConcern)

Parameters

query IMongoQuery

The query (usually a QueryDocument or constructed using the Query builder).

update IMongoUpdate

The update to perform on the matching document.

writeConcern WriteConcern

The write concern to use for this Insert.

Returns

WriteConcernResult

A WriteConcernResult (or null if WriteConcern is disabled).

Validate()

Validates the integrity of this collection.

public virtual ValidateCollectionResult Validate()

Returns

ValidateCollectionResult

A ValidateCollectionResult.

Validate(ValidateCollectionArgs)

Validates the integrity of this collection.

public virtual ValidateCollectionResult Validate(ValidateCollectionArgs args)

Parameters

args ValidateCollectionArgs

The args.

Returns

ValidateCollectionResult

A ValidateCollectionResult.