{"id":30451821,"url":"https://github.com/dumiensky/mongodb.wrapper","last_synced_at":"2025-08-23T14:16:10.839Z","repository":{"id":219808332,"uuid":"310323892","full_name":"dumiensky/MongoDB.Wrapper","owner":"dumiensky","description":"A handy CRUD wrapper with soft deletion over MongoDB.Driver.MongoClient","archived":false,"fork":false,"pushed_at":"2022-01-12T10:22:07.000Z","size":30,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-22T11:41:07.057Z","etag":null,"topics":["crud","mongodb","mongodb-database","soft-delete","wrapper"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dumiensky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2020-11-05T14:27:41.000Z","updated_at":"2024-04-24T18:00:22.000Z","dependencies_parsed_at":"2024-01-29T22:27:28.287Z","dependency_job_id":"934c33ed-3809-4813-affa-81a028f977df","html_url":"https://github.com/dumiensky/MongoDB.Wrapper","commit_stats":null,"previous_names":["dumiensky/mongodb.wrapper"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dumiensky/MongoDB.Wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dumiensky%2FMongoDB.Wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dumiensky%2FMongoDB.Wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dumiensky%2FMongoDB.Wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dumiensky%2FMongoDB.Wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dumiensky","download_url":"https://codeload.github.com/dumiensky/MongoDB.Wrapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dumiensky%2FMongoDB.Wrapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271751927,"owners_count":24814707,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["crud","mongodb","mongodb-database","soft-delete","wrapper"],"created_at":"2025-08-23T14:16:05.987Z","updated_at":"2025-08-23T14:16:10.816Z","avatar_url":"https://github.com/dumiensky.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"## MongoDB.Wrapper\n\nA handy CRUD wrapper with soft deletion over MongoDB.Driver.**MongoClient**.\n\nThis wrapper is designed with _less-code-is-better_ in mind. It uses code-first aproach, just install the nuget and start working on the database!\n\n[Usage](https://github.com/dumiensky/MongoDB.Wrapper#usage) | [Examples](https://github.com/dumiensky/MongoDB.Wrapper#examples) | [List of all methods](https://github.com/dumiensky/MongoDB.Wrapper#list-of-all-methods-exposed-by-the-wrapper)\n\n## Installation\nInstall [NuGet package **MongoDB.Wrapper**](https://www.nuget.org/packages/MongoDB.Wrapper/)\n\n#### dotnet cli: \n`dotnet add package MongoDB.Wrapper`\n\n#### .csproj edit:\n```\n\u003cItemGroup\u003e\n\t\u003cPackageReference Include=\"MongoDB.Wrapper\" Version=\"*\" /\u003e\n\u003c/ItemGroup\u003e\n```\n\n## Usage\n\n#### Dependency Injection\n\n`MongoDB.Wrapper.MongoDb` requires a `MongoDB.Wrapper.Settings.MongoDbSettings` settings instance to work\n\n\u003e_Examples here use **ASP .Net Core DI container** and **appsettings.json** to store the settings. Wrapper is registered as a singleton, because [that's what the docs recommend](http://mongodb.github.io/mongo-csharp-driver/2.0/reference/driver/connecting/#re-use)_\n\n```javascript\n// appsettings.json\n{\n\t\"MongoDbSettings\": {\n\t\t\"ConnectionString\": \"\u003cYOUR CONNECTION STRING\u003e\",\n\t\t\"DatabaseName\": \"\u003cYOUR DATABASE NAME\u003e\"\n\t}\n}\n```\n\n```csharp\n// Startup.cs\npublic void ConfigureServices(IServiceCollection services)\n{\n\t// get the settings from appsettings.json\n\tvar mongoDbSettings = Configuration.GetSection(nameof(MongoDbSettings)).Get\u003cMongoDbSettings\u003e();\n\t\n\t// register the settings and the wrapper\n\tservices.AddSingleton(mongoDbSettings);\n\tservices.AddSingleton\u003cIMongoDb, MongoDb\u003e();\n\t\n\t// OR\n\t\n\t// register only the instance of the wrapper\n\tservices.AddSingleton\u003cIMongoDb\u003e(new MongoDb(mongoDbSettings));\n}\n```\n\n#### Normal class instantiation\n\n```csharp\nvar mongoDbSettings = new MongoDbSettings\n{\n\tConnectionString = \"\u003cYOUR CONNECTION STRING\u003e\",\n\tDatabaseName = \"\u003cYOUR DATABASE NAME\u003e\"\n};\n\nvar mongoDb = new MongoDb(mongoDbSettings);\n```\n\n## Examples\n\nThe wrapper will work on any entity that derive from `MongoDB.Wrapper.Entity` or implement `MongoDB.Wrapper.Abstractions.IEntity`\n```csharp\npublic class Person : Entity\n{\n\tpublic string Name { get; set; }\n\tpublic int Age { get; set; }\n}\n\nvar person = new Person\n{\n\tName = \"Steve\",\n\tAge = 21\n};\n```\n\nEvery method exposed by the wrapper interface (except for `Query\u003c\u003e`) is asynchronous, so the _-Async_ suffix is omitted.\n\n#### Add an entity to the database\n```csharp\n// assigns a new Id to entity and adds it to collection of type TEntity\nawait mongoDb.Add(person);\n\n// id can be accessed straight from the object\nGuid assignedId = person.Id;\n```\n\n#### Access the entities\n```csharp\n// get list of all persons in the database\nvar persons = await mongoDb.Get\u003cPerson\u003e();\n \n// get single entity by its' Id\nvar person = await mongoDb.Get\u003cPerson\u003e(personId);\n\n// get all entities with age of 10\nvar persons = await mongoDb.Get\u003cPerson\u003e(p =\u003e p.Age == 10);\n\n// get all entites with name Frank, older than 18, including the deleted ones\nvar persons = await mongoDb.Get\u003cPerson\u003e(p =\u003e p.Name == \"Frank\" \u0026\u0026 p.Age \u003e 18, includeDeleted: true);\n```\n\n#### Update the entities\n```csharp\nperson.Name = \"Frank\";\n\n// replace the entity by its' Id\nawait mongoDb.Replace(person);\n```\n\n#### List of all methods exposed by the wrapper\n\nReturned type | Method | Description\n------------- | ------ | -----------\n`IMongoQueryable\u003cTEntity\u003e` | **Query\u003c\u003e(includeDeleted)**\u003cbr/\u003e`Query\u003cTEntity\u003e(bool includeDeleted = false)` | Returns an open query to operate on\n`Task` | **Add(entity)**\u003cbr/\u003e`Add\u003cTEntity\u003e(TEntity)` | Assigns a new Id to entity and adds it to collection of type TEntity\n`Task\u003cbool\u003e` | **Any(includeDeleted)**\u003cbr/\u003e`Any\u003cTEntity\u003e(bool includeDeleted = false)` | Returns whether the collection of type TEntity contains entites\n`Task\u003cbool\u003e` | **Any(predicate, includeDeleted)**\u003cbr/\u003e`Any\u003cTEntity\u003e(Expression\u003cFunc\u003cTEntity, bool\u003e\u003e predicate, bool includeDeleted = false)` | Returns whether the collection of type TEntity contains entites matching the predicate\n`Task\u003cint\u003e` | **Count(includeDeleted)**\u003cbr/\u003e`Count\u003cTEntity\u003e(bool includeDeleted = false)` | Returns the count of entites in the collection of type TEntity\n`Task\u003cint\u003e` | **Count(predicate, includeDeleted)**\u003cbr/\u003e`Count\u003cTEntity\u003e(Expression\u003cFunc\u003cTEntity, bool\u003e\u003e predicate, bool includeDeleted = false)` | Returns the count of entites in the collection of type TEntity that match given predicate\n`Task\u003cTEntity\u003e` | **Get(id)**\u003cbr/\u003e`Get\u003cTEntity\u003e(Guid id)` | Returns entity of type TEntity, which Id equals passed Guid. Default if not found\n`Task\u003cList\u003cTEntity\u003e\u003e` | **Get(includeDeleted)**\u003cbr/\u003e`Get\u003cTEntity\u003e(bool includeDeleted = false)` | Returns list of entities from collection of type TEntity\n`Task\u003cList\u003cTEntity\u003e\u003e` | **Get(predicate, includeDeleted)**\u003cbr/\u003e`Get\u003cTEntity\u003e(Expression\u003cFunc\u003cTEntity, bool\u003e\u003e predicate, bool includeDeleted = false)` | Returns list of entities from collection of type TEntity, that match the predicate\n`Task\u003cTEntity\u003e` | **FirstOrDefault(predicate, includeDeleted)**\u003cbr/\u003e`FirstOrDefault\u003cTEntity\u003e(Expression\u003cFunc\u003cTEntity, bool\u003e\u003e predicate, bool includeDeleted = false)` | Returns the first entity from collection of type TEntity, that matches the predicate\n`Task\u003cTEntity\u003e` | **SingleOrDefault(predicate, includeDeleted)**\u003cbr/\u003e`SingleOrDefault\u003cTEntity\u003e(Expression\u003cFunc\u003cTEntity, bool\u003e\u003e predicate, bool includeDeleted = false)` | Returns the entity from collection of type TEntity, that matches the predicate. If more than one entity matches the predicate, an exception is thrown\n`Task\u003cbool\u003e` | **Replace(entity)**\u003cbr/\u003e`Replace\u003cTEntity\u003e(TEntity entity)` | Replaces the object of type TEntity with passed object, compared by IEntity.Id. If IEntity.Id equals default, entity is added. When entity with given id is not found, an exception is thrown.\n`Task\u003cbool\u003e` | **Delete(id)**\u003cbr/\u003e`Delete\u003cTEntity\u003e(Guid id)` | Soft deletes (sets Deleted flag) on entity with given id. Throws an exception if the entity doesn't exist.\n`Task\u003cbool\u003e` | **Restore(id)**\u003cbr/\u003e`Restore\u003cTEntity\u003e(Guid id)` | Reverts a soft delete (un-sets Deleted flag) of an entity with given id. Throws an exception if the entity doesn't exist.\n`Task\u003cbool\u003e` | **DeleteHard**\u003cbr/\u003e`DeleteHard\u003cTEntity\u003e(Guid id)` | Deleted an entity with given id from the database. This is irreversible. Throws an exception if the entity doesn't exist.\n\n## Roadmap\n\n1. `Update()` method that will update only given properties of an entity\n\n**Feel free to create an Issue or a Pull Request**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdumiensky%2Fmongodb.wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdumiensky%2Fmongodb.wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdumiensky%2Fmongodb.wrapper/lists"}