MongoTracker.Core
1.0.3
dotnet add package MongoTracker.Core --version 1.0.3
NuGet\Install-Package MongoTracker.Core -Version 1.0.3
<PackageReference Include="MongoTracker.Core" Version="1.0.3" />
<PackageVersion Include="MongoTracker.Core" Version="1.0.3" />
<PackageReference Include="MongoTracker.Core" />
paket add MongoTracker.Core --version 1.0.3
#r "nuget: MongoTracker.Core, 1.0.3"
#:package MongoTracker.Core@1.0.3
#addin nuget:?package=MongoTracker.Core&version=1.0.3
#tool nuget:?package=MongoTracker.Core&version=1.0.3
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
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.
User-Friendly Interface:
- Easy entity registration in the tracker.
- Seamless integration with existing projects.
Flexibility:
- Supports any entity type.
- Configurable entity identifiers.
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:
Database Initialization:
- Creating collections for authors and books.
- Seeding the database with test data.
Change Tracking:
- Adding, updating, and deleting entities.
- Bulk writing changes to the database.
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 | Versions 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. |
-
.NETStandard 2.1
- MongoDB.Driver (>= 3.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.