{"id":21277626,"url":"https://github.com/vit-orm/vitorm.mongodb","last_synced_at":"2026-02-23T18:33:09.445Z","repository":{"id":256593279,"uuid":"855784932","full_name":"Vit-Orm/Vitorm.MongoDB","owner":"Vit-Orm","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-12T15:12:11.000Z","size":195,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-07T08:15:50.707Z","etag":null,"topics":["database","mongo","mongodb","orm","vitorm"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Vit-Orm.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":"2024-09-11T13:11:23.000Z","updated_at":"2025-01-12T15:03:12.000Z","dependencies_parsed_at":"2024-09-12T00:12:40.658Z","dependency_job_id":"c64a0e5f-28c7-4318-b5dc-6e3eef420e45","html_url":"https://github.com/Vit-Orm/Vitorm.MongoDB","commit_stats":null,"previous_names":["vit-orm/vitorm.mongodb"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Vit-Orm/Vitorm.MongoDB","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vit-Orm%2FVitorm.MongoDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vit-Orm%2FVitorm.MongoDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vit-Orm%2FVitorm.MongoDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vit-Orm%2FVitorm.MongoDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vit-Orm","download_url":"https://codeload.github.com/Vit-Orm/Vitorm.MongoDB/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vit-Orm%2FVitorm.MongoDB/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264765728,"owners_count":23660622,"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":["database","mongo","mongodb","orm","vitorm"],"created_at":"2024-11-21T10:06:32.179Z","updated_at":"2026-02-23T18:33:09.382Z","avatar_url":"https://github.com/Vit-Orm.png","language":"C#","readme":"﻿\n# Vitorm.MongoDB\nVitorm.MongoDB: an simple orm for MongoDB\n\u003esource address: [https://github.com/Vit-Orm/Vitorm.MongoDB](https://github.com/Vit-Orm/Vitorm.MongoDB \"https://github.com/Vit-Orm/Vitorm.MongoDB\")    \n\n![](https://img.shields.io/github/license/Vit-Orm/Vitorm.MongoDB.svg)  \n![](https://img.shields.io/github/repo-size/Vit-Orm/Vitorm.MongoDB.svg)  ![](https://img.shields.io/github/last-commit/Vit-Orm/Vitorm.MongoDB.svg)  \n \n\n| Build | NuGet |\n| -------- | -------- |\n|![](https://github.com/Vit-Orm/Vitorm.MongoDB/workflows/ki_devops3_build/badge.svg) | [![](https://img.shields.io/nuget/v/Vitorm.MongoDB.svg)](https://www.nuget.org/packages/Vitorm.MongoDB) ![](https://img.shields.io/nuget/dt/Vitorm.MongoDB.svg) |\n\n\n\n\n# Vitorm.MongoDB Documentation\nThis guide will walk you through the steps to set up and use Vitorm.MongoDB.\n\nsupported features:\n\n| feature    |  method   |  remarks   |     |\n| --- | --- | --- | --- |\n|  create table   |  TryCreateTable   |     |     |\n|  drop table   |  TryDropTable   |     |     |\n| --- | --- | --- | --- |\n|  create records   |  Add AddRange   |     |     |\n|  retrieve  records |  Query Get   |     |     |\n|  update records   |  Update UpdateRange ExecuteUpdate  |     |     |\n|  delete records   |  Delete DeleteRange DeleteByKey DeleteByKeys ExecuteDelete   |     |     |\n| --- | --- | --- | --- |\n|  change table   |  ChangeTable    |  change mapping table from database   |   |\n|  change database  |  ChangeDatabase   | change database to be connected  |   |\n| --- | --- | --- | --- |\n|  collection total count   |  TotalCount    |  Collection Total Count without Take and Skip   |   |\n|  collection total count and list  |  ToListAndTotalCount   | query List and TotalCount in one request  |   |\n|     |     |   |   |\n\n\n## Installation\nBefore using Vitorm, install the necessary package:    \n``` bash\ndotnet add package Vitorm.MongoDB\n```\n\n## Minimum viable demo\n\u003e code address: [Program_Min.cs](https://github.com/Vit-Orm/Vitorm.MongoDB/tree/master/test/Vitorm.MongoDB.Console/Program_Min.cs)    \n``` csharp\nusing System;\nusing System.Linq;\nusing System.Threading;\nnamespace App\n{\n    public class Program_Min\n    {\n        static void Main2(string[] args)\n        {\n            // #1 Init\n            using var dbContext = new Vitorm.MongoDB.DbContext(\"mongodb://mongoadmin:mongoadminsecret@localhost:27017\");\n            dbContext.TryDropTable\u003cUser\u003e();\n            dbContext.TryCreateTable\u003cUser\u003e();\n            dbContext.Add(new User { id = 1, name = \"lith\" });\n            Thread.Sleep(2000);\n\n            // #2 Query\n            var user = dbContext.Get\u003cUser\u003e(1);\n            var users = dbContext.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToList();\n        }\n\n        // Entity Definition\n        [System.ComponentModel.DataAnnotations.Schema.Table(\"User\")]\n        public class User\n        {\n            [System.ComponentModel.DataAnnotations.Key]\n            public int id { get; set; }\n            public string name { get; set; }\n            public DateTime? birth { get; set; }\n            public int? fatherId { get; set; }\n        }\n    }\n}\n```\n\n\n## Full Example\n\u003e This example provides a comprehensive guide to utilizing Vitorm for basic and advanced database operations while maintaining lightweight performance.    \n\u003e code address: [Program.cs](https://github.com/Vit-Orm/Vitorm.MongoDB/tree/master/test/Vitorm.MongoDB.Console/Program.cs)    \n``` csharp\nusing System;\nusing System.Linq;\nusing Vitorm;\nnamespace App\n{\n    public class Program\n    {\n        static void Main(string[] args)\n        {\n            // #1 Configures Vitorm\n            using var dbContext = new Vitorm.MongoDB.DbContext(\"mongodb://mongoadmin:mongoadminsecret@localhost:27017\");\n\n            // #2 Create Table\n            dbContext.TryDropTable\u003cUser\u003e();\n            dbContext.TryCreateTable\u003cUser\u003e();\n\n            // #3 Insert Records\n            dbContext.Add(new User { id = 1, name = \"lith\" });\n            dbContext.AddRange(new[] {\n                new User {   id = 2, name = \"lith\", fatherId = 1 },\n                new User {   id = 3, name = \"lith\", fatherId = 1 }\n            });\n\n            // #4 Query Records\n            {\n                var user = dbContext.Get\u003cUser\u003e(1);\n                var users = dbContext.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToList();\n                var sql = dbContext.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToExecuteString();\n            }\n\n            // #5 Update Records\n            dbContext.Update(new User { id = 1, name = \"lith1\" });\n            dbContext.UpdateRange(new[] {\n                new User {   id = 2, name = \"lith2\", fatherId = 1 },\n                new User {   id = 3, name = \"lith3\", fatherId = 2 }\n            });\n            //dbContext.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\"))\n            //    .ExecuteUpdate(u =\u003e new User { name = \"Lith\" + u.id });\n\n            // #6 Delete Records\n            dbContext.Delete\u003cUser\u003e(new User { id = 1 });\n            dbContext.DeleteRange(new[] {\n                new User {  id = 2 },\n                new User {  id = 3 }\n            });\n            dbContext.DeleteByKey\u003cUser\u003e(1);\n            dbContext.DeleteByKeys\u003cUser, int\u003e(new[] { 1, 2 });\n            //dbContext.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\"))\n            //    .ExecuteDelete();\n\n            // #7 Join Queries\n\n            // #8 Transactions\n\n            // #9 Database Functions\n        }\n\n        // Entity Definition\n        [System.ComponentModel.DataAnnotations.Schema.Table(\"User\")]\n        public class User\n        {\n            [System.ComponentModel.DataAnnotations.Key]\n            public int id { get; set; }\n            public string name { get; set; }\n            public DateTime? birth { get; set; }\n            public int? fatherId { get; set; }\n        }\n    }\n}\n```\n\n## Explanation   \n1. **Setup**: Initializes the database and configures Vitorm.\n2. **Create Table**: Drops and recreates the `User` table.\n3. **Insert Records**: Adds single and multiple user records.\n4. **Query Records**: Retrieves user records using various querying methods.\n5. **Update Records**: Updates single and multiple user records.\n6. **Delete Records**: Deletes single and multiple user records.\n7. **Join Queries**: Performs a join operation between user and father records.\n8. **Transactions**: Demonstrates nested transactions and rollback/commit operations.\n9. **Database Functions**: Uses custom database functions in queries.\n\n\n\n# Vitorm.Data Documentation    \nVitorm.Data is a static class that allows you to use Vitorm without explicitly creating or disposing of a DbContext.    \n \n## Installation    \nBefore using Vitorm.Data, install the necessary package:    \n``` bash\ndotnet add package Vitorm.Data\ndotnet add package Vitorm.MongoDB\n```\n\n## Config settings\n``` json\n// appsettings.json\n{\n  \"Vitorm\": {\n    \"Data\": [\n      {\n        \"provider\": \"MongoDB\",\n        \"namespace\": \"App\",\n        \"connectionString\": \"mongodb://mongoadmin:mongoadminsecret@localhost:27017\"\n      }\n    ]\n  }\n}\n```\n\n## Minimum viable demo\n\u003e After configuring the `appsettings.json` file, you can directly perform queries without any additional configuration or initialization, `Vitorm.Data` is that easy to use.    \n\u003e code address: [Program_Min.cs](https://github.com/Vit-Orm/Vitorm/tree/master/test/Vitorm.Data.Console/Program_Min.cs)    \n``` csharp\nusing Vitorm;\nnamespace App\n{\n    public class Program_Min\n    {\n        static void Main2(string[] args)\n        {\n            //  Query Records\n            var user = Data.Get\u003cUser\u003e(1);\n            var users = Data.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToList();\n        }\n\n        // Entity Definition\n        [System.ComponentModel.DataAnnotations.Schema.Table(\"User\")]\n        public class User\n        {\n            [System.ComponentModel.DataAnnotations.Key]\n            public int id { get; set; }\n            public string name { get; set; }\n            public DateTime? birth { get; set; }\n            public int? fatherId { get; set; }\n        }\n    }\n}\n\n```\n\n## Full Example    \n\u003e code address: [Program.cs](https://github.com/Vit-Orm/Vitorm/tree/master/test/Vitorm.Data.Console/Program.cs)    \n``` csharp\nusing Vitorm;\n\nnamespace App\n{\n    public class Program\n    {\n        static void Main(string[] args)\n        {\n            // #1 No need to init Vitorm.Data\n\n            // #2 Create Table\n            Data.TryDropTable\u003cUser\u003e();\n            Data.TryCreateTable\u003cUser\u003e();\n\n            // #3 Insert Records\n            Data.Add(new User { id = 1, name = \"lith\" });\n            Data.AddRange(new[] {\n                new User { id = 2, name = \"lith\", fatherId = 1 },\n                new User { id = 3, name = \"lith\", fatherId = 1 }\n            });\n\n            // #4 Query Records\n            {\n                var user = Data.Get\u003cUser\u003e(1);\n                var users = Data.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToList();\n                var sql = Data.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToExecuteString();\n            }\n\n            // #5 Update Records\n            Data.Update(new User { id = 1, name = \"lith1\" });\n            Data.UpdateRange(new[] {\n                new User { id = 2, name = \"lith2\", fatherId = 1 },\n                new User { id = 3, name = \"lith3\", fatherId = 2 }\n            });\n            Data.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\"))\n                .ExecuteUpdate(u =\u003e new User { name = \"Lith\" + u.id });\n\n            // #6 Delete Records\n            Data.Delete\u003cUser\u003e(new User { id = 1, name = \"lith1\" });\n            Data.DeleteRange(new[] {\n                new User { id = 2, name = \"lith2\", fatherId = 1 },\n                new User { id = 3, name = \"lith3\", fatherId = 2 }\n            });\n            Data.DeleteByKey\u003cUser\u003e(1);\n            Data.DeleteByKeys\u003cUser, int\u003e(new[] { 1, 2 });\n            Data.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\"))\n                .ExecuteDelete();\n\n            // #7 Join Queries\n\n            // #8 Transactions\n\n        }\n\n        // Entity Definition\n        [System.ComponentModel.DataAnnotations.Schema.Table(\"User\")]\n        public class User\n        {\n            [System.ComponentModel.DataAnnotations.Key]\n            public int id { get; set; }\n            public string name { get; set; }\n            public DateTime? birth { get; set; }\n            public int? fatherId { get; set; }\n        }\n    }\n}\n```\n\n\n# Examples:  \n[Test Example](https://github.com/Vit-Orm/Vitorm.MongoDB/tree/master/test/Vitorm.MongoDB.MsTest)    \n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvit-orm%2Fvitorm.mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvit-orm%2Fvitorm.mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvit-orm%2Fvitorm.mongodb/lists"}