-
Notifications
You must be signed in to change notification settings - Fork 1
Updates MongoDB.Driver to version 3.2.1 and adds optional parameters. #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f7127ff
9c0b133
d5af22f
83da6a1
c960815
765795f
786e3ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ name: Delete build main | |
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - 'Frends.MongoDB.Delete/**' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| name: Index build main | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - 'Frends.MongoDB.Index/**' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build: | ||
| uses: FrendsPlatform/FrendsTasks/.github/workflows/linux_build_main.yml@main | ||
| with: | ||
| workdir: Frends.MongoDB.Index | ||
| prebuild_command: docker-compose -f ./Frends.MongoDB.Index.Tests/Files/docker-compose.yml up -d | ||
| secrets: | ||
| badge_service_api_key: ${{ secrets.BADGE_SERVICE_API_KEY }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: Index build test | ||
|
|
||
| on: | ||
| push: | ||
| branches-ignore: | ||
| - master | ||
| paths: | ||
| - 'Frends.MongoDB.Index/**' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build: | ||
| uses: FrendsPlatform/FrendsTasks/.github/workflows/linux_build_test.yml@main | ||
| with: | ||
| workdir: Frends.MongoDB.Index | ||
| prebuild_command: docker-compose -f ./Frends.MongoDB.Index.Tests/Files/docker-compose.yml up -d | ||
| secrets: | ||
| badge_service_api_key: ${{ secrets.BADGE_SERVICE_API_KEY }} | ||
| test_feed_api_key: ${{ secrets.TASKS_TEST_FEED_API_KEY }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| name: Index release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build: | ||
| uses: FrendsPlatform/FrendsTasks/.github/workflows/release.yml@main | ||
| with: | ||
| workdir: Frends.MongoDB.Index | ||
| secrets: | ||
| feed_api_key: ${{ secrets.TASKS_FEED_API_KEY }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ name: Insert build main | |
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - 'Frends.MongoDB.Insert/**' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ name: Query build main | |
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - 'Frends.MongoDB.Query/**' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ | |
| using MongoDB.Driver; | ||
| using System.IO; | ||
| using System.Threading.Tasks; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Runtime.Caching; | ||
| using System.Linq; | ||
|
|
||
| namespace Frends.MongoDB.Delete; | ||
|
|
||
|
|
@@ -14,15 +17,18 @@ namespace Frends.MongoDB.Delete; | |
| /// </summary> | ||
| public class MongoDB | ||
| { | ||
| /// <summary> | ||
| /// MongoDB delete operation. | ||
| /// [Documentation](https://tasks.frends.com/tasks/frends-tasks/Frends.MongoDB.Delete) | ||
| /// </summary> | ||
| /// <param name="input">Input parameters.</param> | ||
| /// <param name="connection">Connection parameters.</param> | ||
| /// <param name="cancellationToken">Token generated by Frends to stop this task.</param> | ||
| /// <returns>Object { bool Success, long Count }</returns> | ||
| public static async Task<Result> Delete([PropertyTab] Input input, [PropertyTab] Connection connection, CancellationToken cancellationToken) | ||
| internal static readonly ObjectCache ClientCache = MemoryCache.Default; | ||
| private static readonly CacheItemPolicy _cachePolicy = new() { SlidingExpiration = TimeSpan.FromHours(1) }; | ||
|
|
||
| /// <summary> | ||
| /// MongoDB delete operation. | ||
| /// [Documentation](https://tasks.frends.com/tasks/frends-tasks/Frends.MongoDB.Delete) | ||
| /// </summary> | ||
| /// <param name="input">Input parameters.</param> | ||
| /// <param name="connection">Connection parameters.</param> | ||
| /// <param name="cancellationToken">Token generated by Frends to stop this task.</param> | ||
| /// <returns>Object { bool Success, long Count }</returns> | ||
| public static async Task<Result> Delete([PropertyTab] Input input, [PropertyTab] Connection connection, CancellationToken cancellationToken) | ||
| { | ||
| var collection = GetMongoCollection(connection.ConnectionString, connection.Database, connection.CollectionName); | ||
|
|
||
|
|
@@ -41,7 +47,10 @@ public static async Task<Result> Delete([PropertyTab] Input input, [PropertyTab] | |
| } | ||
|
|
||
| case InputType.Filter: | ||
| return new Result(true, await DeleteOperation(input, BsonDocument.Parse(input.Filter), collection, cancellationToken)); | ||
| if (string.IsNullOrWhiteSpace(input.Filter)) | ||
| throw new ArgumentException("Filter string missing."); | ||
|
|
||
| return new Result(true, await DeleteOperation(input, BsonDocument.Parse(input.Filter), collection, cancellationToken)); | ||
|
|
||
| case InputType.Filters: | ||
| long count = 0; | ||
|
|
@@ -80,31 +89,48 @@ private static async Task<long> DeleteOperation(Input input, BsonDocument filter | |
| } | ||
| } | ||
|
|
||
| private static IMongoCollection<BsonDocument> GetMongoCollection(string connectionString, string database, string collectionName) | ||
| { | ||
| try | ||
| { | ||
| var dataBase = GetMongoDatabase(connectionString, database); | ||
| var collection = dataBase.GetCollection<BsonDocument>(collectionName); | ||
| return collection; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| throw new Exception($"GetMongoCollection error: {ex}"); | ||
| } | ||
| } | ||
| private static IMongoCollection<BsonDocument> GetMongoCollection(string connectionString, string database, string collectionName) | ||
| { | ||
| try | ||
| { | ||
| var dataBase = GetMongoDatabase(connectionString, database, collectionName); | ||
| var collection = dataBase.GetCollection<BsonDocument>(collectionName); | ||
| return collection; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| throw new Exception($"GetMongoCollection error: {ex}"); | ||
| } | ||
| } | ||
|
|
||
| private static IMongoDatabase GetMongoDatabase(string connectionString, string database) | ||
| { | ||
| try | ||
| { | ||
| var mongoClient = new MongoClient(connectionString); | ||
| var dataBase = mongoClient.GetDatabase(database); | ||
| return dataBase; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| throw new Exception($"GetMongoDatabase error: {ex}"); | ||
| } | ||
| } | ||
| private static IMongoDatabase GetMongoDatabase(string connectionString, string database, string collectionName) | ||
| { | ||
| var cacheKey = GetMongoDbCacheKey(connectionString, database, collectionName); | ||
|
|
||
| if (ClientCache.Get(cacheKey) is IMongoDatabase mongoDatabase) | ||
| { | ||
| return mongoDatabase; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var mongoClient = new MongoClient(connectionString); | ||
| var dataBase = mongoClient.GetDatabase(database); | ||
|
|
||
| ClientCache.Add(cacheKey, dataBase, _cachePolicy); | ||
|
|
||
| return dataBase; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| throw new Exception($"GetMongoDatabase error: {ex}"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| [ExcludeFromCodeCoverage] | ||
| private static string GetMongoDbCacheKey(string connectionString, string database, string collectionName) | ||
| { | ||
| return $"{connectionString.GetHashCode()}:{database}:{collectionName}"; | ||
| } | ||
|
Comment on lines
+92
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent ❓ Verification inconclusiveConsider unit tests for caching behavior While the caching implementation looks good, ensure that unit tests verify the caching behavior works as expected - particularly that connections are reused when expected and that expired cache entries are properly recreated. 🏁 Script executed: #!/bin/bash
# Check if there are tests covering the caching functionality
rg -A 5 "ClientCache" --glob "*.Tests.cs"Length of output: 190 Here’s a new shell script to re-verify whether any test files (using a more relaxed filename filter) reference caching (i.e. the Please run this script and share its output so we can further validate whether caching behavior is covered by unit tests. 🏁 Script executed: #!/bin/bash
# Searching for caching test references using a relaxed glob pattern.
rg -A 5 "ClientCache" --glob "*test*.cs"Length of output: 311 Action: Add unit tests to verify caching behavior While the caching implementation itself appears solid, my investigation did not uncover any tests verifying that the caching works as intended. Please confirm manually if tests exist elsewhere; otherwise, ensure that unit tests are added covering the following scenarios:
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update method signature in GetMongoCollection
This method should be updated to match the signature changes in the main Delete.cs file, which now includes collection name in the GetMongoDatabase method call.
📝 Committable suggestion