-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMongoHelper.cs
94 lines (83 loc) · 3.29 KB
/
IMongoHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//Copyright © 2023 Mandala Consulting, LLC MIT License
//Created by Alexander Fields
using MongoDB.Driver;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Optimization.Repository
{
/// <summary>
/// Make sure you set the MongoDB Instance before calling the classes in this
/// </summary>
public interface IMongoHelper
{
/// <summary>
/// The Databaes
/// </summary>
IMongoDatabase database { get; set; }
/// <summary>
/// db name for easier eaccess
/// </summary>
public string dbName { get; set; }
/// <summary>
/// Add a Document to MongoDB
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collectionName"></param>
/// <param name="document"></param>
/// <returns></returns>
Task CreateDocumentAsync<T>(string collectionName, T document);
/// <summary>
/// Create Instance of the Database
/// </summary>
/// <param name="dbName"></param>
/// <param name="connectionString"></param>
/// <returns></returns>
IMongoDatabase CreateMongoDbInstance(string dbName, string connectionString);
/// <summary>
/// Be Careful
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collectionName"></param>
/// <param name="filter"></param>
/// <returns></returns>
Task<DeleteResult> DeleteDocumentAsync<T>(string collectionName, FilterDefinition<T> filter);
/// <summary>
/// Get All documents in collection
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collectionName"></param>
/// <returns></returns>
Task<List<T>> GetAllDocumentsAsync<T>(string collectionName);
/// <summary>
/// Get a Mongo Document
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collectionName"></param>
/// <param name="filter"></param>
/// <returns></returns>
Task<List<T>> GetFilteredDocumentsAsync<T>(string collectionName, FilterDefinition<T> filter);
/// <summary>
/// Tests the connection to the database
/// </summary>
/// <returns>Will return a List of Collection Names if it worked otherwise returns null</returns>
List<string> TestConnection();
/// <summary>
/// Replaces a document
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collectionName"></param>
/// <param name="filter"></param>
/// <param name="document"></param>
/// <returns></returns>
Task<ReplaceOneResult> ReplaceDocumentAsync<T>(string collectionName, FilterDefinition<T> filter, T document);
/// <summary>
/// Updates a document
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collectionName"></param>
/// <param name="filter"></param>
/// <param name="updateDefinition"></param>
/// <returns></returns>
Task<UpdateResult> UpdateDocumentAsync<T>(string collectionName, FilterDefinition<T> filter, UpdateDefinition<T> updateDefinition);
}
}