Interface IMongoDbRepositoryBase<TDocument>
Provides base repository functionality for interacting with MongoDB for a specific document type.
public interface IMongoDbRepositoryBase<TDocument> where TDocument : class
Type Parameters
TDocumentThe type of the document to manage in MongoDB.
Methods
AddOrUpdateAsync(string, TDocument, CancellationToken)
Adds or updates a document in the MongoDB collection.
Task<bool> AddOrUpdateAsync(string documentId, TDocument document, CancellationToken cancellationToken)
Parameters
documentIdstringThe unique identifier for the document.
documentTDocumentThe document to be added or updated.
cancellationTokenCancellationTokenThe cancellation token.
Returns
GetByIdAsync(string, CancellationToken)
Retrieves a document from MongoDB by its ID.
Task<TDocument?> GetByIdAsync(string documentId, CancellationToken cancellationToken)
Parameters
documentIdstringThe unique identifier of the document.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TDocument>
The document if found, or
nullif not found.
RemoveAsync(string, CancellationToken)
Removes a document from the MongoDB collection.
Task<bool> RemoveAsync(string documentId, CancellationToken cancellationToken)
Parameters
documentIdstringThe unique identifier of the document to remove.
cancellationTokenCancellationTokenThe cancellation token.