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
database
MongoDatabaseThe database that contains this collection.
name
stringThe name of the collection.
settings
MongoCollectionSettingsThe 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
args
AggregateArgsThe 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
AggregateArgsThe 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
CountArgsThe 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
IMongoQueryThe 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
IMongoIndexKeysThe 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
IMongoIndexKeysThe indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).
options
IMongoIndexOptionsThe 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
stringThe 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
stringThe key of the field.
query
IMongoQueryThe 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
DistinctArgsThe 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
stringThe 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
stringThe key of the field.
query
IMongoQueryThe 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
DropIndex(IMongoIndexKeys)
Drops an index on this collection.
public virtual CommandResult DropIndex(IMongoIndexKeys keys)
Parameters
keys
IMongoIndexKeysThe 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
keyNames
string[]The names of the indexed fields.
Returns
DropIndexByName(string)
Drops an index on this collection.
public virtual CommandResult DropIndexByName(string indexName)
Parameters
indexName
stringThe 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
keys
IMongoIndexKeysThe 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
IMongoIndexKeysThe indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).
options
IMongoIndexOptionsThe 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
TypeThe 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
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
FindAndModifyArgsThe 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
query
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortBy
IMongoSortByThe sort order to select one of the matching documents.
update
IMongoUpdateThe 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
query
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortBy
IMongoSortByThe sort order to select one of the matching documents.
update
IMongoUpdateThe update to apply to the matching document.
fields
IMongoFieldsWhich fields of the modified document to return in the FindAndModifyResult.
returnNew
boolWhether to return the new or old version of the modified document in the FindAndModifyResult.
upsert
boolWhether 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
query
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortBy
IMongoSortByThe sort order to select one of the matching documents.
update
IMongoUpdateThe update to apply to the matching document.
returnNew
boolWhether 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
query
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortBy
IMongoSortByThe sort order to select one of the matching documents.
update
IMongoUpdateThe update to apply to the matching document.
returnNew
boolWhether to return the new or old version of the modified document in the FindAndModifyResult.
upsert
boolWhether 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
args
FindAndRemoveArgsThe 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
query
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
sortBy
IMongoSortByThe 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
documentType
TypeThe nominal type of the documents.
query
IMongoQueryThe 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
query
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
Returns
- 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
TypeThe 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
TypeThe nominal type of the documents.
args
FindOneArgsThe 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
TypeThe type to deserialize the documents as.
query
IMongoQueryThe 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
FindOneArgsThe 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
IMongoQueryThe 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
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
BsonValueThe 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
TypeThe type to deserialize the documents as.
args
GeoHaystackSearchArgsThe 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
documentType
TypeThe type to deserialize the documents as.
x
doubleThe x coordinate of the starting location.
y
doubleThe y coordinate of the starting location.
options
IMongoGeoHaystackSearchOptionsThe 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
args
GeoHaystackSearchArgsThe args.
Returns
- GeoHaystackSearchResult<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
doubleThe x coordinate of the starting location.
y
doubleThe y coordinate of the starting location.
options
IMongoGeoHaystackSearchOptionsThe options for the geoHaystack search (null if none).
Returns
- GeoHaystackSearchResult<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
TypeThe type to deserialize the documents as.
args
GeoNearArgsThe 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
documentType
TypeThe type to deserialize the documents as.
query
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
x
doubleThe x coordinate of the starting location.
y
doubleThe y coordinate of the starting location.
limit
intThe 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
documentType
TypeThe type to deserialize the documents as.
query
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
x
doubleThe x coordinate of the starting location.
y
doubleThe y coordinate of the starting location.
limit
intThe maximum number of results returned.
options
IMongoGeoNearOptionsThe 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
args
GeoNearArgsThe args.
Returns
- 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
x
doubleThe x coordinate of the starting location.
y
doubleThe y coordinate of the starting location.
limit
intThe maximum number of results returned.
Returns
- 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
x
doubleThe x coordinate of the starting location.
y
doubleThe y coordinate of the starting location.
limit
intThe maximum number of results returned.
options
IMongoGeoNearOptionsThe GeoNear command options (usually a GeoNearOptionsDocument or constructed using the GeoNearOptions builder).
Returns
- 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
GetStatsArgsThe 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
GroupArgsThe 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
keyFunction
BsonJavaScriptA JavaScript function that returns the key value to group on.
initial
BsonDocumentInitial value passed to the reduce function for each group.
reduce
BsonJavaScriptA JavaScript function that is called for each matching document in a group.
finalize
BsonJavaScriptA 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
keys
IMongoGroupByThe names of the fields to group on.
initial
BsonDocumentInitial value passed to the reduce function for each group.
reduce
BsonJavaScriptA JavaScript function that is called for each matching document in a group.
finalize
BsonJavaScriptA 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
key
stringThe name of the field to group on.
initial
BsonDocumentInitial value passed to the reduce function for each group.
reduce
BsonJavaScriptA JavaScript function that is called for each matching document in a group.
finalize
BsonJavaScriptA 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
IMongoIndexKeysThe 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
stringThe 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
TypeThe nominal type of the document to insert.
document
objectThe 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
TypeThe nominal type of the document to insert.
document
objectThe document to insert.
options
MongoInsertOptionsThe 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
TypeThe nominal type of the document to insert.
document
objectThe document to insert.
writeConcern
WriteConcernThe 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
TypeThe nominal type of the documents to insert.
documents
IEnumerableThe 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
TypeThe nominal type of the documents to insert.
documents
IEnumerableThe documents to insert.
options
MongoInsertOptionsThe 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
TypeThe nominal type of the documents to insert.
documents
IEnumerableThe documents to insert.
writeConcern
WriteConcernThe 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
MongoInsertOptionsThe 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
WriteConcernThe 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
TNominalTypeThe 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
TNominalTypeThe document to insert.
options
MongoInsertOptionsThe 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
TNominalTypeThe document to insert.
writeConcern
WriteConcernThe 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
MapReduceArgsThe 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
documentType
TypeType of the document.
args
ParallelScanArgsThe 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
IMongoQueryThe 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
flags
RemoveFlagsThe 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
flags
RemoveFlagsThe flags for this Remove (see RemoveFlags).
writeConcern
WriteConcernThe 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
writeConcern
WriteConcernThe 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
RemoveArgsThe 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
WriteConcernThe 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
nominalType
TypeThe type of the document to save.
document
objectThe document to save.
options
MongoInsertOptionsThe 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
TypeThe type of the document to save.
document
objectThe document to save.
writeConcern
WriteConcernThe 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
TNominalTypeThe 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
TNominalTypeThe document to save.
options
MongoInsertOptionsThe 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
TNominalTypeThe document to save.
writeConcern
WriteConcernThe 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
update
IMongoUpdateThe 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
update
IMongoUpdateThe update to perform on the matching document.
options
MongoUpdateOptionsThe 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
update
IMongoUpdateThe update to perform on the matching document.
flags
UpdateFlagsThe 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
update
IMongoUpdateThe update to perform on the matching document.
flags
UpdateFlagsThe flags for this Update.
writeConcern
WriteConcernThe 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
IMongoQueryThe query (usually a QueryDocument or constructed using the Query builder).
update
IMongoUpdateThe update to perform on the matching document.
writeConcern
WriteConcernThe 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
args
ValidateCollectionArgsThe args.