MongoTracker.Core 1.0.3

dotnet add package MongoTracker.Core --version 1.0.3
                    
NuGet\Install-Package MongoTracker.Core -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MongoTracker.Core" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MongoTracker.Core" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="MongoTracker.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MongoTracker.Core --version 1.0.3
                    
#r "nuget: MongoTracker.Core, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MongoTracker.Core@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MongoTracker.Core&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=MongoTracker.Core&version=1.0.3
                    
Install as a Cake Tool

MongoTracker

MongoTracker is a lightweight ORM (Object-Relational Mapping) library for MongoDB that automatically tracks changes in entities and performs bulk database operations. It simplifies working with MongoDB by providing a convenient interface for managing entities and their changes.

Key Features

  1. Change Tracking:

    • Automatic tracking of entity changes (insert, update, delete).
    • Support for bulk write operations (BulkWrite).
    • Granular updates for complex documents, including nested objects and collections.
  2. User-Friendly Interface:

    • Easy entity registration in the tracker.
    • Seamless integration with existing projects.
  3. Flexibility:

    • Supports any entity type.
    • Configurable entity identifiers.
  4. Performance:

    • Minimizes database queries through bulk operations.
    • Updates only modified fields, reducing database load.

Installation

To use MongoTracker in your project, add it as a NuGet dependency:

dotnet add package MongoTracker.Core

Usage

1. Initializing the Tracker

To start using MongoTracker, create an instance of the tracker by specifying the entity type and its identifier.

var mongoTracker = new MongoTracker<Guid, Book>(tk => tk.Id);  

2. Adding Entities to the Tracker

Entities can be added individually or as a list. The tracker automatically monitors changes.

var book = new Book { Id = Guid.NewGuid(), Title = "Sample Book" };  
mongoTracker.Add(book);  

var anotherBook = await mongoDbContext.Books  
    .AsQueryable()  
    .FirstOrDefaultAsync(b => b.Id == idToFind);  
anotherBook = mongoTracker.Track(anotherBook);  

3. Bulk Writing Changes

After adding entities, changes can be written to the database in a single operation.

await mongoDbContext.Books.BulkWriteAsync(mongoTracker.Commit());  

4. Granular Change Updates

MongoTracker tracks changes even in complex documents, including nested objects and collections. With proper entity configuration, the library detects modifications and updates only the changed fields.

Example:

var book = new Book  
{  
    Id = Guid.NewGuid(),  
    Title = "Sample Book",  
    Chapters = new List<BookChapter>  
    {  
        new BookChapter { Name = "Chapter 1", StartPage = 1, EndPage = 10 }  
    }  
};  

mongoTracker.Add(book);  

// Modify the chapter name  
book.Chapters[0].Name = "Updated Chapter 1";  

// The tracker detects the change and updates only the 'Name' field in the 'Chapters' collection.  
await mongoDbContext.Books.BulkWriteAsync(mongoTracker.Commit());  

Sample Project (MongoTracker.Sample)

The repository includes a sample project, MongoTracker.Sample, demonstrating the library's core features. The example covers:

  1. Database Initialization:

    • Creating collections for authors and books.
    • Seeding the database with test data.
  2. Change Tracking:

    • Adding, updating, and deleting entities.
    • Bulk writing changes to the database.
  3. Working with Different Entity Types:

    • Authors, books, chapters, and audiobooks.

License

MongoTracker is distributed under the MIT License.

Feedback

If you have questions, suggestions, or encounter issues, please create an issue in the project repository.


MongoTracker is a simple yet powerful tool for MongoDB that helps you efficiently manage data in your application. Try it in your project and experience its convenience and performance!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 143 6/16/2025
1.0.2 143 6/14/2025
1.0.1 700 6/11/2025
1.0.0 798 6/11/2025