{"id":24042442,"url":"https://github.com/imperugo/mongodb.driver.extensions","last_synced_at":"2025-04-19T20:45:41.456Z","repository":{"id":65419964,"uuid":"159233801","full_name":"imperugo/MongoDB.Driver.Extensions","owner":"imperugo","description":"A good repository base for your mongo db","archived":false,"fork":false,"pushed_at":"2023-03-04T00:19:44.000Z","size":58,"stargazers_count":3,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T09:46:27.317Z","etag":null,"topics":["csharp","mongodb","repository"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imperugo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-26T21:15:49.000Z","updated_at":"2023-10-10T03:47:30.000Z","dependencies_parsed_at":"2024-06-21T16:41:30.523Z","dependency_job_id":"a8247843-6c80-4ddb-a1b3-c1bfcfd5d1ad","html_url":"https://github.com/imperugo/MongoDB.Driver.Extensions","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imperugo%2FMongoDB.Driver.Extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imperugo%2FMongoDB.Driver.Extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imperugo%2FMongoDB.Driver.Extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imperugo%2FMongoDB.Driver.Extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imperugo","download_url":"https://codeload.github.com/imperugo/MongoDB.Driver.Extensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249795898,"owners_count":21326780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","mongodb","repository"],"created_at":"2025-01-08T22:55:29.198Z","updated_at":"2025-04-19T20:45:41.431Z","avatar_url":"https://github.com/imperugo.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoDB.Driver.Extensions\n\n[![Nuget](https://img.shields.io/nuget/v/MongoDB.Driver.Extensions?style=flat-square)](https://www.nuget.org/packages/MongoDB.Driver.Extensions/)\n[![Nuget](https://img.shields.io/nuget/vpre/MongoDB.Driver.Extensions?style=flat-square)](https://www.nuget.org/packages/MongoDB.Driver.Extensions/)\n[![GitHub](https://img.shields.io/github/license/imperugo/MongoDB.Driver.Extensions?style=flat-square)](https://github.com/imperugo/MongoDB.Driver.Extensions/blob/main/LICENSE)\n\n\n**MongoDB.Driver.Extensions** is a library that extends [MongoDB.Driver](https://docs.mongodb.com/ecosystem/drivers/csharp/) allowing you a set of functionality needed by common applications.\nThe library is completely compatible with the **.Net Standard 2.0**\n\n## What can it be used for?\nThe idea behind this library is to make easier the common operation around a document you have persisted into MongoDb.\n\nFor example you have:\n\n* **Save or update** a document;\n* **Insert** a new document;\n* **Update** a document;\n* **Delete** a document;\n* **Check** if a document exists into your database;\n* **Insert many** documents in a single roundtrip;\n* **Update many** documents in a single roundtrip;\n* **Retrieve** a document **by Id**;\n* **Handling pagination**;\n* **Count** the number of documents;\n\nAll 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.\n\n##How to install it\nMongoDB.Driver.Extensions is available via NuGet, so to install is enough to do \n\n```\nPM\u003e Install-Package MongoDB.Driver.Extensions\n```\n\n## How to configure it\n\nTo 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:\n\n```csharp\npublic class User : DocumentBase\u003cObjectId\u003e\n{\n\tpublic string Firstname { get; set; }\n\tpublic string Lastname { get; set; }\n\tpublic string Email { get; set; }\n\tpublic Guid CompanyId { get; set; }\n}\n```\n\n\u003e In this example I'm using an `ObjectId` and database key, but of course you can change it with your favourite type (string, Guid, and so on).\n\nNow is time to create your repository:\n\n```csharp\ninternal class UserRepository : RepositoryBase\u003cUser, ObjectId\u003e\n{\n    public UserRepository( IMongoClient mongoClient)\n        : base(mongoClient, \"MyDatabase\", \"MyCollectionName\")\n    {\n    }\n}\n```\n\nThe next step is the configuration and the `IMongoClient` :\n\n```csharp\nvar conf = new MongoDbDatabaseConfiguration();\nconf.ConnectionString = \"mongodb://localhost:27017\n\nIMongoClient client = new MongoClient(conf.ConnectionString);\n\n```\n\nIn you are in Asp.Net Core:\n\n```csharp\nservices.AddMongoDb(x =\u003e x.ConnectionString = \"mongodb://mongodbhost:27017/sample\");\n\nservices.AddSingleton\u003cIRepository\u003cUser, ObjectId\u003e, UserRepository\u003e();\n\n\n```\n\nNow, in your service, you can do someting like this:\n\n```csharp\npublic class MyService : IMyService\n{\n\tprivate readonly IRepository\u003cUser,ObjectId\u003e userRepository;\n\t\n\tpublic MyService(IRepository\u003cUser,ObjectId\u003e userRepository)\n    {\n    \tthis.userRepository = userRepository;\n    }\n    \n    public Task\u003cIPagedResult\u003cUser\u003e\u003e DoSomething(int pageIndex, int pageSize, Guid companyId)\n    {\n    \tvar request = new SimplePagedRequest();\n    \trequest.PageIndex = pageIndex;\n    \trequest.PageSize = pageSize;\n    \t\n    \tvar filter = Builders\u003cUser\u003e.Filter.Eq(x =\u003e x.CompanyId, companyId);\n    \t\n    \treturn this.userRepository.GetPagedListAsync(request,filter);\n    }\n}\n```\n## Sample\n\nTake a look [here](https://github.com/imperugo/MongoDB.Driver.Extensions/tree/master/sample/MongoDb.Driver.Extensions.Sample.AspNetCore)\n\n## License\n\nImperugo.HttpRequestToCurl [MIT](https://github.com/imperugo/MongoDB.Driver.Extensions/blob/main/LICENSE) licensed.\n\n### Contributing\n\nThanks to all the people who already contributed!\n\n\u003ca href=\"https://github.com/imperugo/MongoDB.Driver.Extensions/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contributors-img.web.app/image?repo=imperugo/MongoDB.Driver.Extensions\" /\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimperugo%2Fmongodb.driver.extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimperugo%2Fmongodb.driver.extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimperugo%2Fmongodb.driver.extensions/lists"}