Class MongoCollectionExtensions
- Namespace
- MongoDB.Driver
- Assembly
- Cratis.Arc.MongoDB.dll
Extension methods for MongoDB.Driver.IMongoCollection<TDocument>.
public static class MongoCollectionExtensions
- Inheritance
-
MongoCollectionExtensions
- Inherited Members
Methods
FindByIdAsync<T, TId>(IMongoCollection<T>, TId)
Find a single document based on Id - asynchronous.
public static Task<T?> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id)
Parameters
collectionIMongoCollection<T>MongoDB.Driver.IMongoCollection<TDocument> to extend.
idTIdId of document.
Returns
- Task<T>
The document if found, default if not.
Type Parameters
TType of document.
TIdType of identifier.
FindById<T, TId>(IMongoCollection<T>, TId)
Find a single document based on Id.
public static T? FindById<T, TId>(this IMongoCollection<T> collection, TId id)
Parameters
collectionIMongoCollection<T>MongoDB.Driver.IMongoCollection<TDocument> to extend.
idTIdId of document.
Returns
- T
The document if found, default if not.
Type Parameters
TType of document.
TIdType of identifier.
ObserveById<TDocument, TId>(IMongoCollection<TDocument>, TId)
Observe a document by id without query-context paging, sorting, or counting.
public static ISubject<TDocument> ObserveById<TDocument, TId>(this IMongoCollection<TDocument> collection, TId id)
Parameters
collectionIMongoCollection<TDocument>The collection to observe.
idTIdThe document id.
Returns
- ISubject<TDocument>
The observable document.
Type Parameters
TDocumentThe document type.
TIdThe id type.
ObserveById<TDocument, TId>(IMongoCollection<TDocument>, TId, bool)
Create an observable query that will observe a single document based on Id of the document in the collection for changes matching the filter criteria.
public static ISubject<TDocument> ObserveById<TDocument, TId>(this IMongoCollection<TDocument> collection, TId id, bool ignoreQueryContext)
Parameters
collectionIMongoCollection<TDocument>MongoDB.Driver.IMongoCollection<TDocument> to extend.
idTIdThe identifier of the document to observe.
ignoreQueryContextboolRetained for compatibility; has no effect for single-result observations, which always read the full filtered source without client paging, sorting, or total count updates.
Returns
- ISubject<TDocument>
An System.Reactive.Subjects.ISubject<T> with an instance of the type; emits default when no document matches — after the observed document is deleted, or when the initial query finds none.
Type Parameters
TDocumentType of document in the collection.
TIdType of id - key.
ObserveSingle<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>?, FindOptions?)
Observe a single matching document without query-context paging, sorting, or counting.
public static ISubject<TDocument> ObserveSingle<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument>? filter = null, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>The collection to observe.
filterFilterDefinition<TDocument>Optional filter.
optionsFindOptionsOptional find options.
Returns
- ISubject<TDocument>
The observable document.
Type Parameters
TDocumentThe document type.
ObserveSingle<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>?, bool, FindOptions?)
Create an observable query that will observe the collection for changes matching the filter criteria.
public static ISubject<TDocument> ObserveSingle<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument>? filterDefinition, bool ignoreQueryContext, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>MongoDB.Driver.IMongoCollection<TDocument> to extend.
filterDefinitionFilterDefinition<TDocument>The MongoDB filter.
ignoreQueryContextboolRetained for compatibility; has no effect for single-result observations, which always read the full filtered source without client paging, sorting, or total count updates.
optionsFindOptionsOptional options.
Returns
- ISubject<TDocument>
An System.Reactive.Subjects.ISubject<T> with a single instance of the type; emits default when no document matches — after the observed document is deleted, after an update or replace moves it out of the filter, or when the initial query finds none.
Type Parameters
TDocumentType of document in the collection.
Examples
collection.ObserveSingle(filterDefinition, ignoreQueryContext: true).
ObserveSingle<TDocument>(IMongoCollection<TDocument>, bool, FilterDefinition<TDocument>?, FindOptions?)
Observe a single matching document with the compatibility query-context option before the MongoDB filter.
public static ISubject<TDocument> ObserveSingle<TDocument>(this IMongoCollection<TDocument> collection, bool ignoreQueryContext, FilterDefinition<TDocument>? filter = null, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>MongoDB.Driver.IMongoCollection<TDocument> to extend.
ignoreQueryContextboolRetained for compatibility; has no effect for single-result observations, which always read the full filtered source without client paging, sorting, or total count updates.
filterFilterDefinition<TDocument>Optional filter.
optionsFindOptionsOptional options.
Returns
- ISubject<TDocument>
An System.Reactive.Subjects.ISubject<T> with a single instance of the type; emits default when no document matches — after the observed document is deleted, after an update or replace moves it out of the filter, or when the initial query finds none.
Type Parameters
TDocumentType of document in the collection.
ObserveSingle<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>?, FindOptions?)
Observe a single matching document without query-context paging, sorting, or counting.
public static ISubject<TDocument> ObserveSingle<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>>? filter, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>The collection to observe.
filterExpression<Func<TDocument, bool>>Optional filter.
optionsFindOptionsOptional find options.
Returns
- ISubject<TDocument>
The observable document.
Type Parameters
TDocumentThe document type.
ObserveSingle<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>?, bool, FindOptions?)
Create an observable query that will observe the collection for changes matching the filter criteria.
public static ISubject<TDocument> ObserveSingle<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>>? filter, bool ignoreQueryContext, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>MongoDB.Driver.IMongoCollection<TDocument> to extend.
filterExpression<Func<TDocument, bool>>Optional filter.
ignoreQueryContextboolRetained for compatibility; has no effect for single-result observations, which always read the full filtered source without client paging, sorting, or total count updates.
optionsFindOptionsOptional options.
Returns
- ISubject<TDocument>
An System.Reactive.Subjects.ISubject<T> with a single instance of the type; emits default when no document matches — after the observed document is deleted, after an update or replace moves it out of the filter, or when the initial query finds none.
Type Parameters
TDocumentType of document in the collection.
Observe<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>?, FindOptions?)
Observe matching documents using the current query context.
public static ISubject<IEnumerable<TDocument>> Observe<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument>? filter = null, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>The collection to observe.
filterFilterDefinition<TDocument>Optional filter.
optionsFindOptionsOptional find options.
Returns
- ISubject<IEnumerable<TDocument>>
The observable documents.
Type Parameters
TDocumentThe document type.
Observe<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>?, bool, FindOptions?)
Create an observable query that will observe the collection for changes matching the filter criteria.
public static ISubject<IEnumerable<TDocument>> Observe<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument>? filterDefinition, bool ignoreQueryContext, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>MongoDB.Driver.IMongoCollection<TDocument> to extend.
filterDefinitionFilterDefinition<TDocument>The MongoDB filter.
ignoreQueryContextboolWhether to read the full filtered source without client paging, sorting, or total count updates.
optionsFindOptionsOptional options.
Returns
- ISubject<IEnumerable<TDocument>>
System.Reactive.Subjects.ISubject<T> with a collection of the type for the collection.
Type Parameters
TDocumentType of document in the collection.
Examples
collection.Observe(filterDefinition, ignoreQueryContext: true).
Observe<TDocument>(IMongoCollection<TDocument>, bool, FilterDefinition<TDocument>?, FindOptions?)
Observe matching documents with the query-context option before the MongoDB filter.
public static ISubject<IEnumerable<TDocument>> Observe<TDocument>(this IMongoCollection<TDocument> collection, bool ignoreQueryContext, FilterDefinition<TDocument>? filter = null, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>MongoDB.Driver.IMongoCollection<TDocument> to extend.
ignoreQueryContextboolWhether to ignore client paging, sorting, and total count updates.
filterFilterDefinition<TDocument>Optional filter.
optionsFindOptionsOptional options.
Returns
- ISubject<IEnumerable<TDocument>>
System.Reactive.Subjects.ISubject<T> with a collection of the type for the collection.
Type Parameters
TDocumentType of document in the collection.
Observe<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>?, FindOptions?)
Observe matching documents using the current query context.
public static ISubject<IEnumerable<TDocument>> Observe<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>>? filter, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>The collection to observe.
filterExpression<Func<TDocument, bool>>Optional filter.
optionsFindOptionsOptional find options.
Returns
- ISubject<IEnumerable<TDocument>>
The observable documents.
Type Parameters
TDocumentThe document type.
Observe<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>?, bool, FindOptions?)
Create an observable query that will observe the collection for changes matching the filter criteria.
public static ISubject<IEnumerable<TDocument>> Observe<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>>? filter, bool ignoreQueryContext, FindOptions? options = null)
Parameters
collectionIMongoCollection<TDocument>MongoDB.Driver.IMongoCollection<TDocument> to extend.
filterExpression<Func<TDocument, bool>>Optional filter.
ignoreQueryContextboolWhether to read the full filtered source without client paging, sorting, or total count updates.
optionsFindOptionsOptional options.
Returns
- ISubject<IEnumerable<TDocument>>
System.Reactive.Subjects.ISubject<T> with a collection of the type for the collection.
Type Parameters
TDocumentType of document in the collection.