Repository.Mongo
2.2.5
See the version list below for details.
dotnet add package Repository.Mongo --version 2.2.5
NuGet\Install-Package Repository.Mongo -Version 2.2.5
<PackageReference Include="Repository.Mongo" Version="2.2.5" />
paket add Repository.Mongo --version 2.2.5
#r "nuget: Repository.Mongo, 2.2.5"
// Install Repository.Mongo as a Cake Addin
#addin nuget:?package=Repository.Mongo&version=2.2.5
// Install Repository.Mongo as a Cake Tool
#tool nuget:?package=Repository.Mongo&version=2.2.5
MongoRepository
Repository pattern for MongoDB with extended features
MongoDB Driver Version
2.11.4
Definition
Model
You don't need to create a model, but if you are doing so you need to extend Entity
// If you are able to define your model
public class User : Entity
{
public string Username { get; set; }
public string Password { get; set; }
}
Repository
There are multiple base constructors, read summaries of others
public class UserRepository : Repository<User>
{
public UserRepository (string connectionString) : base (connectionString) { }
// Custom method
public User FindbyUsername (string username)
{
return First (i => i.Username == username);
}
// Custom method2
public void UpdatePassword (User item, string newPassword)
{
repo.Update (item, i => i.Password, newPassword);
}
// Custom async method
public async Task<User> FindbyUsernameAsync (string username)
{
return await FirstAsync (i => i.Username == username);
}
}
If you want to create a repository for already defined non-entity model
public class UserRepository : Repository<Entity<User>>
{
public UserRepository (string connectionString) : base (connectionString) { }
// Custom method
public User FindbyUsername (string username)
{
return First (i => i.Content.Username == username);
}
}
Usage
Each method has multiple overloads, read method summary for additional parameters
UserRepository repo = new UserRepository ("mongodb://localhost/sample")
// Get
User user = repo.Get ("58a18d16bc1e253bb80a67c9");
// Insert
User item = new User ()
{
Username = "username",
Password = "password"
};
repo.Insert (item);
// Update
// Single property
repo.Update (item, i => i.Username, "newUsername");
// Multiple property
// Updater has many methods like Inc, Push, CurrentDate, etc.
var update1 = Updater.Set (i => i.Username, "oldUsername");
var update2 = Updater.Set (i => i.Password, "newPassword");
repo.Update (item, update1, update2);
// All entity
item.Username = "someUsername";
repo.Replace (item);
// Delete
repo.Delete (item);
// Queries - all queries has filter, order and paging features
var first = repo.First ();
var last = repo.Last ();
var search = repo.Find (i => i.Username == "username");
var allItems = repo.FindAll ();
// Utils
var any = repo.Any (i => i.Username.Contains ("user"));
// Count
// Get number of filtered documents
var count = repo.Count (p => p.Age > 20);
// EstimatedCount
// Get number of all documents
var count = repo.EstimatedCount ();
List of Functions
Delete(T entity)
Task<bool> DeleteAsync(T entity)
Delete(Expression<Func<T, bool>> filter)
Task<bool> DeleteAsync(Expression<Func<T, bool>> filter)
IEnumerable<T> Find(Expression<Func<T, bool>> filter, int pageIndex, int size)
IEnumerable<T> Find(Expression<Func<T, bool>> filter, Expression<Func<T, object>> order, int pageIndex, int size)
IEnumerable<T> FindAll(int pageIndex, int size)
IEnumerable<T> FindAll(Expression<Func<T, object>> order, int pageIndex, int size)
T First()
T First(FilterDefinition<T> filter)
T First(Expression<Func<T, bool>> filter)
T First(Expression<Func<T, bool>> filter, Expression<Func<T, object>> order)
T First(Expression<Func<T, bool>> filter, Expression<Func<T, object>> order, bool isDescending)
Task<T> FirstAsync(FilterDefinition<T> filter)
Task<T> FirstAsync(Expression<Func<T, bool>> filter)
T Last()
T Last(FilterDefinition<T> filter)
T Last(Expression<Func<T, bool>> filter)
T Last(Expression<Func<T, bool>> filter, Expression<Func<T, object>> order)
T Last(Expression<Func<T, bool>> filter, Expression<Func<T, object>> order, bool isDescending)
void Replace(IEnumerable<T> entities)
T FindOneAndUpdate(FilterDefinition<T> filter, UpdateDefinition<T> update, FindOneAndUpdateOptions<T> options = null)
T FindOneAndUpdate(Expression<Func<T, bool>> filter, UpdateDefinition<T> update, FindOneAndUpdateOptions<T> options = null)
Task<T> FindOneAndUpdateAsync(FilterDefinition<T> filter, UpdateDefinition<T> update, FindOneAndUpdateOptions<T> options = null)
Task<T> FindOneAndUpdateAsync(Expression<Func<T, bool>> filter, UpdateDefinition<T> update, FindOneAndUpdateOptions<T> options = null)
bool Update<TField>(T entity, Expression<Func<T, TField>> field, TField value)
Task<bool> UpdateAsync<TField>(T entity, Expression<Func<T, TField>> field, TField value)
bool Any(Expression<Func<T, bool>> filter)
bool Update<TField>(FilterDefinition<T> filter, Expression<Func<T, TField>> field, TField value)
bool Update(FilterDefinition<T> filter, params UpdateDefinition<T>[] updates)
bool Update(Expression<Func<T, bool>> filter, params UpdateDefinition<T>[] updates)
Task<bool> UpdateAsync(FilterDefinition<T> filter, params UpdateDefinition<T>[] updates)
Task<bool> UpdateAsync(Expression<Func<T, bool>> filter, params UpdateDefinition<T>[] updates)
Task<bool> UpdateAsync<TField>(FilterDefinition<T> filter, Expression<Func<T, TField>> field, TField value)
long EstimatedCount()
long Count(Expression<Func<T, bool>> filter)
long EstimatedCount(EstimatedDocumentCountOptions options)
Task<long> EstimatedCountAsync()
Task<long> CountAsync(Expression<Func<T, bool>> filter)
Task<long> EstimatedCountAsync(EstimatedDocumentCountOptions options)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.5 is compatible. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5.2
- Microsoft.Extensions.Configuration (>= 1.1.1)
- MongoDB.Driver (>= 2.11.4)
- Polly (>= 5.9.0)
-
.NETStandard 1.5
- Microsoft.Extensions.Configuration (>= 1.1.1)
- MongoDB.Driver (>= 2.11.4)
- NETStandard.Library (>= 1.6.1)
- Polly (>= 5.9.0)
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 1.1.1)
- MongoDB.Driver (>= 2.11.4)
- Polly (>= 5.9.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Repository.Mongo:
Package | Downloads |
---|---|
Repository.Mongo.Cached
This package contains cached repository which is based on Repository.Mongo package. Cache object should be based on Microsoft.Extensions.Caching |
|
Repository.Mongo.Cqrs
This package contains base implementations for CQRS pattern on Repository.Mongo package. It is also possible to use Repository.Mongo.Cached package |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.3.4 | 3,842 | 10/21/2021 |
2.3.3 | 440 | 10/1/2021 |
2.3.2 | 407 | 10/1/2021 |
2.3.1 | 1,411 | 8/10/2021 |
2.2.9 | 1,219 | 7/4/2021 |
2.2.5 | 8,892 | 11/4/2020 |
2.2.1 | 7,686 | 9/29/2019 |
2.1.6 | 1,361 | 6/8/2019 |
2.1.3 | 1,178 | 4/9/2019 |
2.1.2 | 1,419 | 1/12/2019 |
2.1.1 | 1,558 | 11/7/2018 |
2.0.6 | 4,060 | 5/2/2018 |
2.0.4 | 3,947 | 9/5/2017 |
2.0.3 | 1,529 | 8/3/2017 |
2.0.2 | 1,625 | 4/4/2017 |
2.0.0 | 1,417 | 3/31/2017 |
1.0.5 | 1,184 | 1/8/2017 |
1.0.4 | 1,287 | 10/16/2016 |
1.0.3 | 1,215 | 6/21/2016 |
1.0.2 | 1,306 | 5/28/2016 |
1.0.1 | 1,152 | 1/30/2016 |
1.0.0 | 1,278 | 1/18/2016 |
Async functions