/* * dbMango * * Copyright 2025 Deutsche Bank AG * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using MongoDB.Bson; using MongoDB.Driver; namespace Rms.Risk.Mango.Pivot.Core.MongoDb; /// /// Non templated portion of mongo interface /// public interface IGenericMongoDbServices { /// Name of the collection this instance operates on string CollectionName { get; } /// Number of records in the collection long Count { get; } /// /// Delete the entire collection. For temporary collections only! /// void DeleteCollection(); /// /// Run aggregate query async. No support for reties. /// /// Aggregation pipeline query (JSON) /// Maximum number of documents fetched. Use -1 for no limit. /// /// IAsyncEnumerable> AggregateAsync(string jsonPipeline, int maxFetchSize = -1, CancellationToken token = default); /// /// Run aggregate query async. No support for reties. /// /// Aggregation pipeline query (JSON) /// Maximum number of documents fetched. Use -1 for no limit. /// /// IAsyncEnumerable AggregateAsyncRaw(string jsonPipeline, int maxFetchSize = -1, CancellationToken token = default); /// /// Explain the command execution plan /// Task ExplainAsync(string command, CancellationToken token = default); /// /// Clear all data for given COB/layer/book/root /// /// /// /// /// ??? /// Task ClearCOBAsync(DateTime cob, string? layer = null, string? book = null, string? root = null, CancellationToken token = default); } /// /// MongoDB interface for collections where all documents have type T (generic argument) /// /// public interface IMongoDbService : IGenericMongoDbServices { /// /// Insert documents into collection /// /// Data to insert /// If true data will replace existing documents with the same keys /// /// /// Task InsertAsync(IEnumerable data, bool overrideExisting, bool suppressWarning = false, CancellationToken token = default); /// /// Get documents matching the filter /// /// /// Enables retry logic. Warning: it sorting the results. Do not use for large result sets! /// Optional projection definition /// Max number of results returned /// /// IAsyncEnumerable FindAsync(FilterDefinition filter, bool allowRetries = true, ProjectionDefinition? projection = null, int? limit = null, CancellationToken token = default); /// /// Get documents matching the filter /// /// /// /// Task CountAsync(FilterDefinition filter, CancellationToken token = default); /// /// Get only keys matching the filter (not documents!) /// /// /// /// IEnumerable FindKeys(FilterDefinition filter, CancellationToken token = default); /// /// Update document(s) /// /// Filter /// Update definition /// void UpdateOne( FilterDefinition filter, UpdateDefinition update, CancellationToken token = default ); /// /// Replace document /// /// Filter selecting a single document /// New value /// void ReplaceOne( FilterDefinition filter, T doc, CancellationToken token = default ); /// /// Delete documents matching the filter /// /// Filter selecting a single document /// /// Number of deleted documents Task Delete( FilterDefinition filter, CancellationToken token = default ); }