![]() |
VOOZH | about |
dotnet add package MongoDB.Driver.Extensions --version 2.0.2
NuGet\Install-Package MongoDB.Driver.Extensions -Version 2.0.2
<PackageReference Include="MongoDB.Driver.Extensions" Version="2.0.2" />
<PackageVersion Include="MongoDB.Driver.Extensions" Version="2.0.2" />Directory.Packages.props
<PackageReference Include="MongoDB.Driver.Extensions" />Project file
paket add MongoDB.Driver.Extensions --version 2.0.2
#r "nuget: MongoDB.Driver.Extensions, 2.0.2"
#:package MongoDB.Driver.Extensions@2.0.2
#addin nuget:?package=MongoDB.Driver.Extensions&version=2.0.2Install as a Cake Addin
#tool nuget:?package=MongoDB.Driver.Extensions&version=2.0.2Install as a Cake Tool
MongoDB.Driver.Extensions is a library that extends MongoDB.Driver allowing you a set of functionality needed by common applications. The library is completely compatible with the .Net Standard 2.0
The idea behind this library is to make easier the common operation around a document you have persisted into MongoDb.
For example you have:
All the methods available to do in the list above are available in both sync / async version and offers different parameters in order to change the amount of data to work.
##How to install it MongoDB.Driver.Extensions is available via NuGet, so to install is enough to do
PM> Install-Package MongoDB.Driver.Extensions
To use this library the first is to provide all the necessary information to the library. To do that the first thing to do is to create your document:
public class User : DocumentBase<ObjectId>
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Email { get; set; }
public Guid CompanyId { get; set; }
}
In this example I'm using an
ObjectIdand database key, but of course you can change it with your favourite type (string, Guid, and so on).
Now is time to create your repository:
internal class UserRepository : RepositoryBase<User, ObjectId>
{
public UserRepository( IMongoClient mongoClient)
: base(mongoClient, "MyDatabase", "MyCollectionName")
{
}
}
The next step is the configuration and the IMongoClient :
var conf = new MongoDbDatabaseConfiguration();
conf.ConnectionString = "mongodb://localhost:27017
IMongoClient client = new MongoClient(conf.ConnectionString);
In you are in Asp.Net Core:
services.AddMongoDb(x => x.ConnectionString = "mongodb://mongodbhost:27017/sample");
services.AddSingleton<IRepository<User, ObjectId>, UserRepository>();
Now, in your service, you can do someting like this:
public class MyService : IMyService
{
private readonly IRepository<User,ObjectId> userRepository;
public MyService(IRepository<User,ObjectId> userRepository)
{
this.userRepository = userRepository;
}
public Task<IPagedResult<User>> DoSomething(int pageIndex, int pageSize, Guid companyId)
{
var request = new SimplePagedRequest();
request.PageIndex = pageIndex;
request.PageSize = pageSize;
var filter = Builders<User>.Filter.Eq(x => x.CompanyId, companyId);
return this.userRepository.GetPagedListAsync(request,filter);
}
}
Take a look here
Imperugo.HttpRequestToCurl MIT licensed.
Thanks to all the people who already contributed!
<a href="https://github.com/imperugo/MongoDB.Driver.Extensions/graphs/contributors"> <img src="https://contributors-img.web.app/image?repo=imperugo/MongoDB.Driver.Extensions" /> </a>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 NuGet packages that depend on MongoDB.Driver.Extensions:
| Package | Downloads |
|---|---|
|
Elsa.Persistence.MongoDb
Provides MongoDB implementations of various abstractions from various modules. |
|
|
Elsa.MongoDb
Provides MongoDB implementations of various abstractions from various modules. |
This package is not used by any popular GitHub repositories.