{"id":19992180,"url":"https://github.com/AoxeTech/Aoxe.Mongo","last_synced_at":"2025-05-04T11:30:43.540Z","repository":{"id":45466191,"uuid":"119151963","full_name":"AoxeTech/Aoxe.Mongo","owner":"AoxeTech","description":"Provide an easy way to use Mongo as repository and with UpdateMany / DeleteMany in lambda style.","archived":false,"fork":false,"pushed_at":"2024-11-18T12:42:25.000Z","size":286,"stargazers_count":10,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-01T23:08:34.976Z","etag":null,"topics":["mongo","repository","zaabee"],"latest_commit_sha":null,"homepage":"https://github.com/AoxeTech","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/AoxeTech.png","metadata":{"files":{"readme":"README-zh_CN.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-01-27T09:48:12.000Z","updated_at":"2024-11-18T12:42:29.000Z","dependencies_parsed_at":"2024-04-01T14:59:49.710Z","dependency_job_id":"6a12dacc-e0bd-47f5-84e6-5314a0f05d06","html_url":"https://github.com/AoxeTech/Aoxe.Mongo","commit_stats":{"total_commits":122,"total_committers":6,"mean_commits":"20.333333333333332","dds":0.3770491803278688,"last_synced_commit":"d4fd5d9a4b835c3c1df65591a1809be8aa9a2c41"},"previous_names":["mutuduxf/zaabee.mongo","picohex/zaabee.mongo"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AoxeTech%2FAoxe.Mongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AoxeTech%2FAoxe.Mongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AoxeTech%2FAoxe.Mongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AoxeTech%2FAoxe.Mongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AoxeTech","download_url":"https://codeload.github.com/AoxeTech/Aoxe.Mongo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252329140,"owners_count":21730555,"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":["mongo","repository","zaabee"],"created_at":"2024-11-13T04:52:04.033Z","updated_at":"2025-05-04T11:30:42.456Z","avatar_url":"https://github.com/AoxeTech.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# Aoxe.Mongo\n\n[English](README.md) | 简体中文\n\n提供一种简单的方法，将 Mongo 用作存储库，并以 lambda 风格使用 UpdateMany / DeleteMany。\n\n该项目实现了三个软件包：\n\n- Aoxe.Mongo.Abstractions - aoxe mongo 的抽象。\n- Aoxe.Mongo.Client - Aoxe.Mongo.Abstractions 的实现。\n- Aoxe.Mongo - 为 Aoxe.Mongo.Client 提供服务扩展，以简化 IOC 注册。\n\n---\n\n## QuickStart\n\n从 NuGet 安装软件包\n\n```bash\nPM\u003e Install-Package Aoxe.Mongo\n```\n\n将 AoxeMongoClient 注册到 IOC 容器里\n\n```csharp\nserviceCollection.AddAoxeMongo(\"mongodb://localhost:27017\", \"test\");\n```\n\n通过引用 Aoxe.Email.Abstractions 注入 IAoxeMongoClient。\n\n```bash\nPM\u003e Install-Package Aoxe.Mongo.Abstractions\n```\n\n```csharp\npublic class TestRepository\n{\n    private readonly IAoxeMongoClient _mongoClient;\n\n    public TestRepository(IAoxeMongoClient mongoClient)\n    {\n        _mongoClient = mongoClient;\n    }\n}\n```\n\n另外您也可以注入 Lazy\u003cIAoxeMongoClient\u003e。\n\n```csharp\npublic class TestRepository\n{\n    private readonly Lazy\u003cIAoxeMongoClient\u003e _mongoClient;\n\n    public TestRepository(Lazy\u003cIAoxeMongoClient\u003e mongoClient)\n    {\n        _mongoClient = mongoClient;\n    }\n}\n```\n\n```csharp\npublic class TestRepository\n{\n    private readonly IAoxeMongoClient _mongoClient;\n\n    public TestRepository(IAoxeMongoClient mongoClient)\n    {\n        _mongoClient = mongoClient;\n    }\n}\n```\n\n不使用 IOC 的话可以直接实例化 AoxeMongoClient 对象\n\n```bash\nPM\u003e Install-Package Aoxe.Mongo.Client\n```\n\n```csharp\nvar mongoClient = new AoxeMongoClient(\"mongodb://localhost:27017\", \"test\");\n```\n\n现在假设我们有一个这样的 Model class:\n\n```csharp\npublic class TestModel\n{\n    public Guid Id { get; set; }\n    public string Name { get; set; }\n    public int Age { get; set; }\n}\n```\n\n然后我们就可以像使用存储库一样使用 mongo:\n\n新增\n\n```csharp\nmongoClient.Add(model);\nmongoClient.AddRange(models);\n\nawait mongoClient.AddAsync(model);\nawait mongoClient.AddRangeAsync(models);\n```\n\n删除\n\n```csharp\nmongoClient.Delete(model);\nmongoClient.DeleteMany\u003cTestModel\u003e(m =\u003e m.Name == \"apple\");\n\nawait mongoClient.DeleteAsync(model);\nawait mongoClient.DeleteManyAsync\u003cTestModel\u003e(m =\u003e m.Name == \"apple\");\n```\n\n修改\n\n```csharp\nmodel.Name = \"banana\";\nmongoClient.Update(model);\nmongoClient.UpdateMany(() =\u003e\n    m =\u003e m.Name == \"apple\",\n    new TestModel\n    {\n        Age = 22,\n        Name = \"pear\"\n    })\n\nawait mongoClient.UpdateAsync(model);\nawait mongoClient.UpdateManyAsync(() =\u003e\n    m =\u003e m.Name == \"apple\",\n    new TestModel\n    {\n        Age = 22,\n        Name = \"pear\"\n    })\n```\n\n查询\n\n```csharp\nvar query = mongoClient.GetQueryable\u003cTestModel\u003e();\nvar result = query.FirstOrDefault(p =\u003e p.Name == \"pear\");\nvar result = query.Where(p =\u003e names.Contains(p.Name)).ToList();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAoxeTech%2FAoxe.Mongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAoxeTech%2FAoxe.Mongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAoxeTech%2FAoxe.Mongo/lists"}