Skip to content

Commit

Permalink
🔀 Merge pull request #18 from Fedodo/dev
Browse files Browse the repository at this point in the history
✨ Added GetSpecificItemFromCollections
  • Loading branch information
LNA-DEV authored Aug 18, 2023
2 parents 3b28006 + c5d67c2 commit 17ce97a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Fedodo.NuGet.Common/Interfaces/IMongoDbRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ public Task<IEnumerable<T>> GetSpecificPagedFromCollections<T>(string databaseNa
FilterDefinition<T> filter);

public IEnumerable<string> GetCollectionNames(string databaseName);

public Task<T> GetSpecificItemFromCollections<T>(FilterDefinition<T> filter, string databaseName,
IEnumerable<string> collectionNames);
}
13 changes: 12 additions & 1 deletion Fedodo.NuGet.Common/Repositories/MongoDbRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<IEnumerable<T>> GetAllPagedFromCollections<T>(string databaseN

return result;
}

public async Task<IEnumerable<T>> GetSpecificPaged<T>(string databaseName, string collectionName, int pageId,
int pageSize,
SortDefinition<T> sortDefinition, FilterDefinition<T> filter)
Expand Down Expand Up @@ -201,6 +201,17 @@ public async Task<T> GetSpecificItem<T>(FilterDefinition<T> filter, string datab
return result;
}

public async Task<T> GetSpecificItemFromCollections<T>(FilterDefinition<T> filter, string databaseName,
IEnumerable<string> collectionNames)
{
var database = _client.GetDatabase(databaseName);
var collection = AggregateCollections<T>(collectionNames.ToList(), database);

var result = await collection.Match(filter).SingleOrDefaultAsync();

return result;
}

public async Task<IEnumerable<T>> GetSpecificItems<T>(FilterDefinition<T> filter, string databaseName,
string collectionName)
{
Expand Down

0 comments on commit 17ce97a

Please sign in to comment.