Class MongoCollection
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
databaseMongoDatabaseThe database that contains this collection.
namestringThe name of the collection.
settingsMongoCollectionSettingsThe settings to use to access this collection.
Properties
Database
Gets the database that contains this collection.
public virtual MongoDatabase Database { get; }
Property Value
FullName
Gets the fully qualified name of this collection.
public virtual string FullName { get; }
Property Value
Name
Gets the name of this collection.
public virtual string Name { get; }
Property Value
Settings
Gets the settings being used to access this collection.
public virtual MongoCollectionSettings Settings { get; }
Property Value
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
argsAggregateArgsThe 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
argsAggregateArgsThe 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
argsCountArgsThe 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
queryIMongoQueryThe 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
keysIMongoIndexKeysThe 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
keysIMongoIndexKeysThe indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).
optionsIMongoIndexOptionsThe 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
keyNamesstring[]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
keystringThe 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
keystringThe key of the field.
queryIMongoQueryThe 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
argsDistinctArgsThe args.
Returns
- IEnumerable<TValue>
The distint values of the field.
Type Parameters
TValueThe type of the value.
Distinct<TValue>(string)
Returns the distinct values for a given field.
public virtual IEnumerable<TValue> Distinct<TValue>(string key)
Parameters
keystringThe key of the field.
Returns
- IEnumerable<TValue>
The distint values of the field.
Type Parameters
TValueThe 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
keystringThe key of the field.
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
Returns
- IEnumerable<TValue>
The distint values of the field.
Type Parameters
TValueThe 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
DropIndex(IMongoIndexKeys)
Drops an index on this collection.
public virtual CommandResult DropIndex(IMongoIndexKeys keys)
Parameters
keysIMongoIndexKeysThe indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).
Returns
DropIndex(params string[])
Drops an index on this collection.
public virtual CommandResult DropIndex(params string[] keyNames)
Parameters
keyNamesstring[]The names of the indexed fields.
Returns
DropIndexByName(string)
Drops an index on this collection.
public virtual CommandResult DropIndexByName(string indexName)
Parameters
indexNamestringThe name of the index.
Returns
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
keysIMongoIndexKeysThe 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
keysIMongoIndexKeysThe indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).
optionsIMongoIndexOptionsThe 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
keyNamesstring[]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
documentTypeTypeThe nominal type of the documents.
Returns
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>
Type Parameters
TDocumentThe 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
argsFindAndModifyArgsThe args.
Returns
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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortByIMongoSortByThe sort order to select one of the matching documents.
updateIMongoUpdateThe update to apply to the matching document.
Returns
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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortByIMongoSortByThe sort order to select one of the matching documents.
updateIMongoUpdateThe update to apply to the matching document.
fieldsIMongoFieldsWhich fields of the modified document to return in the FindAndModifyResult.
returnNewboolWhether to return the new or old version of the modified document in the FindAndModifyResult.
upsertboolWhether to do an upsert if no matching document is found.
Returns
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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortByIMongoSortByThe sort order to select one of the matching documents.
updateIMongoUpdateThe update to apply to the matching document.
returnNewboolWhether to return the new or old version of the modified document in the FindAndModifyResult.
Returns
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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortByIMongoSortByThe sort order to select one of the matching documents.
updateIMongoUpdateThe update to apply to the matching document.
returnNewboolWhether to return the new or old version of the modified document in the FindAndModifyResult.
upsertboolWhether to do an upsert if no matching document is found.
Returns
FindAndRemove(FindAndRemoveArgs)
Finds one matching document using the supplied args and removes it from this collection.
public virtual FindAndModifyResult FindAndRemove(FindAndRemoveArgs args)
Parameters
argsFindAndRemoveArgsThe args.
Returns
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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortByIMongoSortByThe sort order to select one of the matching documents.
Returns
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
documentTypeTypeThe nominal type of the documents.
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
Returns
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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
Returns
- MongoCursor<TDocument>
Type Parameters
TDocumentThe type to deserialize the documents as.
FindOneAs(Type)
Returns one document in this collection as a TDocument.
public virtual object FindOneAs(Type documentType)
Parameters
documentTypeTypeThe 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
documentTypeTypeThe nominal type of the documents.
argsFindOneArgsThe 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
documentTypeTypeThe type to deserialize the documents as.
queryIMongoQueryThe 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
TDocumentThe 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
argsFindOneArgsThe args.
Returns
- TDocument
A TDocument (or null if not found).
Type Parameters
TDocumentThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
Returns
- TDocument
A TDocument (or null if not found).
Type Parameters
TDocumentThe 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
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
idBsonValueThe id of the document.
Returns
- TDocument
A TDocument (or null if not found).
Type Parameters
TDocumentThe 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
documentTypeTypeThe type to deserialize the documents as.
argsGeoHaystackSearchArgsThe args.
Returns
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
documentTypeTypeThe type to deserialize the documents as.
xdoubleThe x coordinate of the starting location.
ydoubleThe y coordinate of the starting location.
optionsIMongoGeoHaystackSearchOptionsThe options for the geoHaystack search (null if none).
Returns
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
argsGeoHaystackSearchArgsThe args.
Returns
- GeoHaystackSearchResult<TDocument>
Type Parameters
TDocumentThe 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
xdoubleThe x coordinate of the starting location.
ydoubleThe y coordinate of the starting location.
optionsIMongoGeoHaystackSearchOptionsThe options for the geoHaystack search (null if none).
Returns
- GeoHaystackSearchResult<TDocument>
Type Parameters
TDocumentThe type of the found documents.
GeoNearAs(Type, GeoNearArgs)
Runs a GeoNear command on this collection.
public virtual GeoNearResult GeoNearAs(Type documentType, GeoNearArgs args)
Parameters
documentTypeTypeThe type to deserialize the documents as.
argsGeoNearArgsThe args.
Returns
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
documentTypeTypeThe type to deserialize the documents as.
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
xdoubleThe x coordinate of the starting location.
ydoubleThe y coordinate of the starting location.
limitintThe maximum number of results returned.
Returns
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
documentTypeTypeThe type to deserialize the documents as.
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
xdoubleThe x coordinate of the starting location.
ydoubleThe y coordinate of the starting location.
limitintThe maximum number of results returned.
optionsIMongoGeoNearOptionsThe GeoNear command options (usually a GeoNearOptionsDocument or constructed using the GeoNearOptions builder).
Returns
GeoNearAs<TDocument>(GeoNearArgs)
Runs a GeoNear command on this collection.
public virtual GeoNearResult<TDocument> GeoNearAs<TDocument>(GeoNearArgs args)
Parameters
argsGeoNearArgsThe args.
Returns
- GeoNearResult<TDocument>
Type Parameters
TDocumentThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
xdoubleThe x coordinate of the starting location.
ydoubleThe y coordinate of the starting location.
limitintThe maximum number of results returned.
Returns
- GeoNearResult<TDocument>
Type Parameters
TDocumentThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
xdoubleThe x coordinate of the starting location.
ydoubleThe y coordinate of the starting location.
limitintThe maximum number of results returned.
optionsIMongoGeoNearOptionsThe GeoNear command options (usually a GeoNearOptionsDocument or constructed using the GeoNearOptions builder).
Returns
- GeoNearResult<TDocument>
Type Parameters
TDocumentThe 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
argsGetStatsArgsThe 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
argsGroupArgsThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
keyFunctionBsonJavaScriptA JavaScript function that returns the key value to group on.
initialBsonDocumentInitial value passed to the reduce function for each group.
reduceBsonJavaScriptA JavaScript function that is called for each matching document in a group.
finalizeBsonJavaScriptA 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
keysIMongoGroupByThe names of the fields to group on.
initialBsonDocumentInitial value passed to the reduce function for each group.
reduceBsonJavaScriptA JavaScript function that is called for each matching document in a group.
finalizeBsonJavaScriptA 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
keystringThe name of the field to group on.
initialBsonDocumentInitial value passed to the reduce function for each group.
reduceBsonJavaScriptA JavaScript function that is called for each matching document in a group.
finalizeBsonJavaScriptA 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
keysIMongoIndexKeysThe 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
keyNamesstring[]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
indexNamestringThe 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
TDocumentThe 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
TDocumentThe 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
nominalTypeTypeThe nominal type of the document to insert.
documentobjectThe 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
nominalTypeTypeThe nominal type of the document to insert.
documentobjectThe document to insert.
optionsMongoInsertOptionsThe 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
nominalTypeTypeThe nominal type of the document to insert.
documentobjectThe document to insert.
writeConcernWriteConcernThe 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
nominalTypeTypeThe nominal type of the documents to insert.
documentsIEnumerableThe 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
nominalTypeTypeThe nominal type of the documents to insert.
documentsIEnumerableThe documents to insert.
optionsMongoInsertOptionsThe 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
nominalTypeTypeThe nominal type of the documents to insert.
documentsIEnumerableThe documents to insert.
writeConcernWriteConcernThe 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
documentsIEnumerable<TNominalType>The documents to insert.
Returns
- IEnumerable<WriteConcernResult>
A list of WriteConcernResults (or null if WriteConcern is disabled).
Type Parameters
TNominalTypeThe 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
documentsIEnumerable<TNominalType>The documents to insert.
optionsMongoInsertOptionsThe options to use for this Insert.
Returns
- IEnumerable<WriteConcernResult>
A list of WriteConcernResults (or null if WriteConcern is disabled).
Type Parameters
TNominalTypeThe 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
documentsIEnumerable<TNominalType>The documents to insert.
writeConcernWriteConcernThe write concern to use for this Insert.
Returns
- IEnumerable<WriteConcernResult>
A list of WriteConcernResults (or null if WriteConcern is disabled).
Type Parameters
TNominalTypeThe 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
documentTNominalTypeThe document to insert.
Returns
- WriteConcernResult
A WriteConcernResult (or null if WriteConcern is disabled).
Type Parameters
TNominalTypeThe 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
documentTNominalTypeThe document to insert.
optionsMongoInsertOptionsThe options to use for this Insert.
Returns
- WriteConcernResult
A WriteConcernResult (or null if WriteConcern is disabled).
Type Parameters
TNominalTypeThe 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
documentTNominalTypeThe document to insert.
writeConcernWriteConcernThe write concern to use for this Insert.
Returns
- WriteConcernResult
A WriteConcernResult (or null if WriteConcern is disabled).
Type Parameters
TNominalTypeThe 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
argsMapReduceArgsThe args.
Returns
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
documentTypeTypeType of the document.
argsParallelScanArgsThe 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
argsParallelScanArgs<TDocument>The args.
Returns
- ReadOnlyCollection<IEnumerator<TDocument>>
Multiple enumerators, one for each cursor.
Type Parameters
TDocumentThe 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
queryIMongoQueryThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
flagsRemoveFlagsThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
flagsRemoveFlagsThe flags for this Remove (see RemoveFlags).
writeConcernWriteConcernThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
writeConcernWriteConcernThe 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
argsRemoveArgsThe 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
writeConcernWriteConcernThe 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
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
nominalTypeTypeThe type of the document to save.
documentobjectThe document to save.
optionsMongoInsertOptionsThe 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
nominalTypeTypeThe type of the document to save.
documentobjectThe document to save.
writeConcernWriteConcernThe 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
documentTNominalTypeThe document to save.
Returns
- WriteConcernResult
A WriteConcernResult (or null if WriteConcern is disabled).
Type Parameters
TNominalTypeThe 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
documentTNominalTypeThe document to save.
optionsMongoInsertOptionsThe options to use for this Save.
Returns
- WriteConcernResult
A WriteConcernResult (or null if WriteConcern is disabled).
Type Parameters
TNominalTypeThe 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
documentTNominalTypeThe document to save.
writeConcernWriteConcernThe write concern to use for this Insert.
Returns
- WriteConcernResult
A WriteConcernResult (or null if WriteConcern is disabled).
Type Parameters
TNominalTypeThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
updateIMongoUpdateThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
updateIMongoUpdateThe update to perform on the matching document.
optionsMongoUpdateOptionsThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
updateIMongoUpdateThe update to perform on the matching document.
flagsUpdateFlagsThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
updateIMongoUpdateThe update to perform on the matching document.
flagsUpdateFlagsThe flags for this Update.
writeConcernWriteConcernThe 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
queryIMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
updateIMongoUpdateThe update to perform on the matching document.
writeConcernWriteConcernThe 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
Validate(ValidateCollectionArgs)
Validates the integrity of this collection.
public virtual ValidateCollectionResult Validate(ValidateCollectionArgs args)
Parameters
argsValidateCollectionArgsThe args.