Class MongoClient.Collection<TDocument>
An object representing a remote MongoDB collection.
Namespace: Realms.Sync
Assembly: Realm.dll
Syntax
public class MongoClient.Collection<TDocument> where TDocument : class
Type Parameters
Name | Description |
---|---|
TDocument | The managed type that matches the shape of the documents in the collection. |
Properties
| Edit this page View SourceDatabase
Gets the Database this collection belongs to.
Declaration
public MongoClient.Database? Database { get; }
Property Value
Type | Description |
---|---|
MongoClient.Database | The collection's Database or null if the database was automatically inferred with MongoClient.Collection<TDocument>. |
Name
Gets the name of the collection.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
string | The collection name. |
Methods
| Edit this page View SourceAggregateAsync(params object[])
Executes an aggregation pipeline on the collection and returns the results as a MongoDB.Bson.BsonDocument array.
Declaration
public Task<BsonDocument[]> AggregateAsync(params object[] pipeline)
Parameters
Type | Name | Description |
---|---|---|
object[] | pipeline | Documents describing the different pipeline stages using pipeline expressions. |
Returns
Type | Description |
---|---|
Task<BsonDocument[]> | An awaitable Task representing the remote aggregate operation. The result of the task is an array containing the documents returned
by executing the aggregation |
See Also
| Edit this page View SourceAggregateAsync<TProjection>(params object[])
Executes an aggregation pipeline on the collection and returns the results as a TProjection
array.
Declaration
public Task<TProjection[]> AggregateAsync<TProjection>(params object[] pipeline)
Parameters
Type | Name | Description |
---|---|---|
object[] | pipeline | Documents describing the different pipeline stages using pipeline expressions. |
Returns
Type | Description |
---|---|
Task<TProjection[]> | An awaitable Task representing the remote aggregate operation. The result of the task is an array containing the documents returned
by executing the aggregation |
Type Parameters
Name | Description |
---|---|
TProjection | The managed type that matches the shape of the result of the pipeline. |
See Also
| Edit this page View SourceCountAsync(object?, long?)
Counts the number of documents in the collection that match the provided filter
.
Declaration
public Task<long> CountAsync(object? filter = null, long? limit = null)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the find criteria using query operators. If not specified, all documents in the collection will be counted. |
long? | limit | The maximum number of documents to count. If not specified, all documents in the collection are counted. |
Returns
Type | Description |
---|---|
Task<long> | An awaitable Task representing the remote count operation. The result of the task is the number of documents that match the
|
DeleteManyAsync(object?)
Removes one or more documents from a collection. If no documents match the filter
, the collection is not modified.
Declaration
public Task<MongoClient.DeleteResult> DeleteManyAsync(object? filter = null)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the deletion criteria using query operators. If not specified, all documents in the collection will be deleted. |
Returns
Type | Description |
---|---|
Task<MongoClient.DeleteResult> | An awaitable Task<TResult> representing the remote delete many operation. The result of the task contains the number of deleted documents. |
See Also
| Edit this page View SourceDeleteOneAsync(object?)
Removes a single document from a collection. If no documents match the filter
, the collection is not modified.
Declaration
public Task<MongoClient.DeleteResult> DeleteOneAsync(object? filter = null)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the deletion criteria using query operators. If not specified, the first document in the collection will be deleted. |
Returns
Type | Description |
---|---|
Task<MongoClient.DeleteResult> | An awaitable Task<TResult> representing the remote delete one operation. The result of the task contains the number of deleted documents. |
See Also
| Edit this page View SourceFindAsync(object?, object?, object?, long?)
Finds the all documents in the collection up to limit
.
Declaration
public Task<TDocument[]> FindAsync(object? filter = null, object? sort = null, object? projection = null, long? limit = null)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the find criteria using query operators. If not specified, all documents in the collection will be returned. |
object | sort | A document describing the sort criteria. If not specified, the order of the returned documents is not guaranteed. |
object | projection | A document describing the fields to return for all matching documents. If not specified, all fields are returned. |
long? | limit | The maximum number of documents to return. If not specified, all documents in the collection are returned. |
Returns
Type | Description |
---|---|
Task<TDocument[]> | An awaitable Task representing the remote find operation. The result of the task is an array containing the documents that match the find criteria. |
See Also
FindOneAndDeleteAsync(object?, object?, object?)
Finds the first document in the collection that satisfies the query criteria.
Declaration
public Task<TDocument?> FindOneAndDeleteAsync(object? filter = null, object? sort = null, object? projection = null)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the find criteria using query operators. If not specified, all documents in the collection will match the request. |
object | sort | A document describing the sort criteria. If not specified, the order of the returned documents is not guaranteed. |
object | projection | A document describing the fields to return for all matching documents. If not specified, all fields are returned. |
Returns
Type | Description |
---|---|
Task<TDocument> | An awaitable Task<TResult> representing the remote find one operation. The result of the task is the first document that matches the find criteria. |
See Also
| Edit this page View SourceFindOneAndReplaceAsync(object?, TDocument, object?, object?, bool, bool)
Finds the first document in the collection that satisfies the query criteria.
Declaration
public Task<TDocument> FindOneAndReplaceAsync(object? filter, TDocument replacementDoc, object? sort = null, object? projection = null, bool upsert = false, bool returnNewDocument = false)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the find criteria using query operators. If not specified, all documents in the collection will match the request. |
TDocument | replacementDoc | The replacement document. Cannot contain update operator expressions. |
object | sort | A document describing the sort criteria. If not specified, the order of the returned documents is not guaranteed. |
object | projection | A document describing the fields to return for all matching documents. If not specified, all fields are returned. |
bool | upsert | A boolean controlling whether the replace should insert a document if no documents match the |
bool | returnNewDocument | A boolean controlling whether to return the replacement document. If set to |
Returns
Type | Description |
---|---|
Task<TDocument> | An awaitable Task<TResult> representing the remote find one operation. The result of the task is the first document that matches the find criteria. |
See Also
| Edit this page View SourceFindOneAndUpdateAsync(object?, object, object?, object?, bool, bool)
Finds the first document in the collection that satisfies the query criteria.
Declaration
public Task<TDocument> FindOneAndUpdateAsync(object? filter, object updateDocument, object? sort = null, object? projection = null, bool upsert = false, bool returnNewDocument = false)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the find criteria using query operators. If not specified, all documents in the collection will match the request. |
object | updateDocument | A document describing the update. Can only contain update operator expressions. |
object | sort | A document describing the sort criteria. If not specified, the order of the returned documents is not guaranteed. |
object | projection | A document describing the fields to return for all matching documents. If not specified, all fields are returned. |
bool | upsert | A boolean controlling whether the update should insert a document if no documents match the |
bool | returnNewDocument | A boolean controlling whether to return the new updated document. If set to |
Returns
Type | Description |
---|---|
Task<TDocument> | An awaitable Task<TResult> representing the remote find one operation. The result of the task is the first document that matches the find criteria. |
See Also
| Edit this page View SourceFindOneAsync(object?, object?, object?)
Finds the first document in the collection that satisfies the query criteria.
Declaration
public Task<TDocument?> FindOneAsync(object? filter = null, object? sort = null, object? projection = null)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the find criteria using query operators. If not specified, all documents in the collection will match the request. |
object | sort | A document describing the sort criteria. If not specified, the order of the returned documents is not guaranteed. |
object | projection | A document describing the fields to return for all matching documents. If not specified, all fields are returned. |
Returns
Type | Description |
---|---|
Task<TDocument> | An awaitable Task<TResult> representing the remote find one operation. The result of the task is the first document that matches the find criteria. |
See Also
| Edit this page View SourceInsertManyAsync(IEnumerable<TDocument>)
Inserts one or more documents in the collection.
Declaration
public Task<MongoClient.InsertManyResult> InsertManyAsync(IEnumerable<TDocument> docs)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TDocument> | docs | The documents to insert. |
Returns
Type | Description |
---|---|
Task<MongoClient.InsertManyResult> | An awaitable Task<TResult> representing the remote insert many operation. The result of the task
contains the |
See Also
| Edit this page View SourceInsertOneAsync(TDocument)
Inserts the provided document in the collection.
Declaration
public Task<MongoClient.InsertResult> InsertOneAsync(TDocument doc)
Parameters
Type | Name | Description |
---|---|---|
TDocument | doc | The document to insert. |
Returns
Type | Description |
---|---|
Task<MongoClient.InsertResult> | An awaitable Task<TResult> representing the remote insert operation. The result of the task
contains the |
See Also
| Edit this page View SourceUpdateManyAsync(object?, object, bool)
Updates one or more documents in the collection according to the specified arguments.
Declaration
public Task<MongoClient.UpdateResult> UpdateManyAsync(object? filter, object updateDocument, bool upsert = false)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the selection criteria of the update. If not specified, all documents in the collection will be updated. Can only contain query selector expressions. |
object | updateDocument | A document describing the update. Can only contain update operator expressions. |
bool | upsert | A boolean controlling whether the update should insert a document if no documents match the |
Returns
Type | Description |
---|---|
Task<MongoClient.UpdateResult> | An awaitable Task<TResult> representing the remote update many operation. The result of the task
contains information about the number of matched and updated documents, as well as the |
See Also
| Edit this page View SourceUpdateOneAsync(object?, object, bool)
Updates a single document in the collection according to the specified arguments.
Declaration
public Task<MongoClient.UpdateResult> UpdateOneAsync(object? filter, object updateDocument, bool upsert = false)
Parameters
Type | Name | Description |
---|---|---|
object | filter | A document describing the selection criteria of the update. If not specified, the first document in the collection will be updated. Can only contain query selector expressions. |
object | updateDocument | A document describing the update. Can only contain update operator expressions. |
bool | upsert | A boolean controlling whether the update should insert a document if no documents match the |
Returns
Type | Description |
---|---|
Task<MongoClient.UpdateResult> | An awaitable Task<TResult> representing the remote update one operation. The result of the task
contains information about the number of matched and updated documents, as well as the |