Skip to content

Commit 813822c

Browse files
roku674github-actions[bot]dependabot[bot]
authored
Alexander's Anointed Automated Git Helper (#118)
* Alexander's Anointed Automated Git Helper * Auto-increment versions for PR to master * Bump Pomelo.EntityFrameworkCore.MySql from 8.0.2 to 9.0.0 (#116) * Bump Microsoft.EntityFrameworkCore from 8.0.11 to 9.0.13 --- updated-dependencies: - dependency-name: Microsoft.EntityFrameworkCore dependency-version: 9.0.13 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Bump Microsoft.EntityFrameworkCore.InMemory from 8.0.11 to 9.0.13 --- updated-dependencies: - dependency-name: Microsoft.EntityFrameworkCore.InMemory dependency-version: 9.0.13 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Bump Microsoft.NET.Test.Sdk from 18.0.1 to 18.3.0 --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-version: 18.3.0 dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.NET.Test.Sdk dependency-version: 18.3.0 dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.NET.Test.Sdk dependency-version: 18.3.0 dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.NET.Test.Sdk dependency-version: 18.3.0 dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.NET.Test.Sdk dependency-version: 18.3.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Bump Pomelo.EntityFrameworkCore.MySql from 8.0.2 to 9.0.0 --- updated-dependencies: - dependency-name: Pomelo.EntityFrameworkCore.MySql dependency-version: 9.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alexander Fields <Roku674@gmail.com> Co-authored-by: Alexander Fields <fields.alexander@anointedautomation.net> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 8c9ff16 commit 813822c

File tree

6 files changed

+103
-3
lines changed

6 files changed

+103
-3
lines changed

AnointedAutomation.Repository.Mongo/AnointedAutomation.Repository.Mongo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Copyright>Copyright © 2023 Anointed Automation, LLC All rights reserved.</Copyright>
1212
<Description>Repository for Generic Mongo Usage - AnointedAutomation.Repository.Mongo</Description>
1313
<RepositoryUrl>https://github.com/roku674/AnointedAutomation</RepositoryUrl>
14-
<Version>0.0.10</Version>
14+
<Version>0.0.11</Version>
1515
<PackageTags>Mongo</PackageTags>
1616
<PackageReleaseNotes>https://github.com/roku674/AnointedAutomation/pkgs/nuget/AnointedAutomation.Repository.Logging</PackageReleaseNotes>
1717
<Authors>Anointed Automation LLC, Alexander Fields</Authors>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2026 Anointed Automation, LLC. All Rights Reserved.
2+
// Created by Alexander Fields https://www.alexanderfields.me
3+
4+
using System;
5+
using MongoDB.Bson;
6+
using MongoDB.Bson.Serialization.Attributes;
7+
8+
namespace AnointedAutomation.Repository.Mongo
9+
{
10+
/// <summary>
11+
/// Base class for MongoDB documents with common BSON attributes.
12+
/// </summary>
13+
[BsonIgnoreExtraElements]
14+
public abstract class MongoDocument
15+
{
16+
/// <summary>
17+
/// MongoDB ObjectId as string.
18+
/// </summary>
19+
[BsonId]
20+
[BsonRepresentation(BsonType.ObjectId)]
21+
public string Id { get; set; } = string.Empty;
22+
}
23+
24+
/// <summary>
25+
/// Base class for MongoDB documents with audit timestamps.
26+
/// </summary>
27+
[BsonIgnoreExtraElements]
28+
public abstract class AuditableMongoDocument : MongoDocument
29+
{
30+
/// <summary>
31+
/// When the document was created.
32+
/// </summary>
33+
[BsonElement("createdAt")]
34+
public DateTime createdAt { get; set; }
35+
36+
/// <summary>
37+
/// When the document was last updated.
38+
/// </summary>
39+
[BsonElement("updatedAt")]
40+
public DateTime updatedAt { get; set; }
41+
}
42+
}

AnointedAutomation.Repository.Mongo/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The **MongoHelper** library, developed by Anointed Automation, LLC, provides a s
88

99
## Features
1010

11+
- **Base Document Classes**: `MongoDocument` and `AuditableMongoDocument` for consistent entity definitions.
1112
- Simplifies MongoDB connection setup.
1213
- CRUD operations for MongoDB documents:
1314
- Create: Insert documents.
@@ -74,6 +75,46 @@ BsonClassMapRegistrar.RegisterDerivedUser<MyCustomUser>();
7475

7576
This ensures proper BSON serialization for your custom user types in MongoDB.
7677

78+
### Using Base Document Classes
79+
80+
The library provides two abstract base classes for your MongoDB entities:
81+
82+
#### MongoDocument
83+
84+
Basic base class with proper ObjectId handling:
85+
86+
```csharp
87+
using AnointedAutomation.Repository.Mongo;
88+
89+
public class Product : MongoDocument
90+
{
91+
public string Name { get; set; }
92+
public decimal Price { get; set; }
93+
}
94+
```
95+
96+
This gives you:
97+
- `Id` property with `[BsonId]` and `[BsonRepresentation(BsonType.ObjectId)]`
98+
- `[BsonIgnoreExtraElements]` for forward compatibility
99+
100+
#### AuditableMongoDocument
101+
102+
Extends `MongoDocument` with audit timestamps:
103+
104+
```csharp
105+
using AnointedAutomation.Repository.Mongo;
106+
107+
public class Order : AuditableMongoDocument
108+
{
109+
public string CustomerId { get; set; }
110+
public decimal Total { get; set; }
111+
}
112+
```
113+
114+
This adds:
115+
- `createdAt` - creation timestamp (DateTime is a value type)
116+
- `updatedAt` - last update timestamp
117+
77118
### Setting Up MongoHelper
78119

79120
```csharp

AnointedAutomation.Repository.MySql/AnointedAutomation.Repository.MySql.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<ItemGroup>
2323
<ProjectReference Include="..\AnointedAutomation.Logging\AnointedAutomation.Logging.csproj" />
2424
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.13" />
25-
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
25+
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

PROJECT_STRUCTURE_CODE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ All code files in the solution have been documented with XML documentation follo
6060
- Usage guidelines
6161

6262
### 5. AnointedAutomation.Repository.Mongo
63+
- MongoDocument.cs
64+
- Base class for MongoDB documents (`MongoDocument`)
65+
- Auditable base class with timestamps (`AuditableMongoDocument`)
66+
- BSON attribute configuration for ObjectId handling
67+
- Full XML documentation
68+
6369
- MongoHelper.cs
6470
- Full CRUD operation documentation
6571
- Connection management

PROJECT_STRUCTURE_LIBRARIES.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,24 @@ The AnointedAutomation solution contains 7 core libraries targeting .NET 8.0, ea
135135
- Event system for logging and IP banning
136136
- Environment variable configuration: `API_KEY`, `API_KEY_NAME`
137137

138-
### 4. AnointedAutomation.Repository.Mongo v0.0.5
138+
### 4. AnointedAutomation.Repository.Mongo v0.0.10
139139

140140
**Purpose & Functionality:**
141141
- MongoDB database operations wrapper
142142
- Generic CRUD operations with strongly-typed interfaces
143143
- Connection management and logging integration
144+
- Base document classes for MongoDB entities
144145

145146
**Key Classes:**
147+
- `MongoDocument` - Abstract base class for MongoDB documents
148+
- Provides `Id` property with proper `[BsonId]` and `[BsonRepresentation(BsonType.ObjectId)]` attributes
149+
- Includes `[BsonIgnoreExtraElements]` for forward compatibility
150+
- Inherit from this for any MongoDB-persisted entity
151+
152+
- `AuditableMongoDocument` - Base class with audit timestamps
153+
- Extends `MongoDocument` with `createdAt` and `updatedAt` properties (DateTime = value type = camelCase)
154+
- Use for entities requiring creation/modification tracking
155+
146156
- `IMongoHelper` - Interface defining MongoDB operations
147157
- Defines standard CRUD operations
148158
- Connection management methods
@@ -176,6 +186,7 @@ The AnointedAutomation solution contains 7 core libraries targeting .NET 8.0, ea
176186
- MongoDB.Libmongocrypt (1.12.0)
177187

178188
**Public API Surface:**
189+
- Base classes: `MongoDocument`, `AuditableMongoDocument`
179190
- CRUD operations: `CreateDocumentAsync<T>()`, `GetAllDocumentsAsync<T>()`, `UpdateDocumentAsync<T>()`, `DeleteDocumentAsync<T>()`
180191
- Connection management: `CreateMongoDbInstance()`, `TestConnection()`
181192
- Utility methods: `ConnectionStringBuilder()`, `GetIdFromObj<T>()`

0 commit comments

Comments
 (0)