MongoDbService 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MongoDbService --version 3.0.0
                    
NuGet\Install-Package MongoDbService -Version 3.0.0
                    
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.

                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.

                    
Directory.Packages.props

                    
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 MongoDbService --version 3.0.0
                    
#r "nuget: MongoDbService, 3.0.0"
                    
#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 MongoDbService@3.0.0
                    
#: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=MongoDbService&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MongoDbService&version=3.0.0
                    
Install as a Cake Tool

MongoDbService

MongoDbService is an open-source C# class library that provides a wrapper around the official MongoDB.Driver

Features

Contributing

We welcome contributions! If you find a bug, have an idea for improvement, please submit an issue or a pull request on GitHub.

Getting Started

NuGet Package

To include MongoDbService in your project, install the NuGet package:

dotnet add package MongoDbService

Then in your appsettings.json add the following sample configuration and change the values to mtch the details of your MongoDB instance.

"MongoDbSettings": {
  "MongoDatabaseName": "YourDatabaseName",
  "ConnectionString": "mongodb+srv://.........@gpcluster.0bulb.mongodb.net/myDatabase?retryWrites=true&w=majority"
}

After the above is done, you can just Dependency inject the MongoService in your C# class.

For example:

Lets say your had a DTO to represent a record of an IMongoCollection called Vehicle

using MongoDB.Bson.Serialization.Attributes;

namespace YourNameSpace
{
    public sealed class Vehicle
    {
        [BsonId]
        public required string Id { get; init; }
        public required string  Name { get; set; }
    }
}

Then you could have another class called VehicleHandler to add and remove Vehicle instances as follows:

using MongoDB.Driver;
using MongoDbService;

namespace YourNameSpace
{
	public sealed class VehicleHandler
	{
		private IMongoCollection _vehicleCollection;

		public VehicleHandler(
			MongoService mongoService
		)
		{
        _vehicleCollection = mongoService.Database.GetCollection(nameof(Vehicle), new MongoCollectionSettings() { ReadConcern = ReadConcern.Majority, WriteConcern = WriteConcern.WMajority });
		}

		public async Task AddVehicle(string vehicleName)
		{
			await _vehicleCollection.InsertOneAsync(new Vehicle() { Id = Guid.NewGuid().ToString(), Name = vehicleName });
		}

		public async Task RemoveVehicle(string vehicleId)
		{
			return await _vehicleCollection.DeleteOneAsync(Builders.Filter.Eq(v => v.Id, vehicleId));
		}
	}
}

GitHub Repository

Visit our GitHub repository for the latest updates, documentation, and community contributions. https://github.com/prmeyn/MongoDbService

License

This project is licensed under the GNU GENERAL PUBLIC LICENSE.

Happy coding! 🚀🌐📚

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on MongoDbService:

Package Downloads
GeoIpServices

A C# library that provides geolocation information for IP addresses with MongoDB caching. Wraps third-party IP geolocation services (IpStack) to reduce API usage and costs through intelligent caching.

SMSwitch

Package Description

UmbracoExternalStorageWithMongoDB

This package allows you to store your custom data in a NoSQL MongoDB database from Umbraco 17, using MongoDbService. Unlike most NoSQL databases, a MongoDB server can be installed on almost any platform, your laptop or on a Cloud service like AWS, GCP or Azure. It avoids vendor lock in into any specific hosting platform.

MongoDbTokenManager

Create, store and verify one-time tokens (OTTs) in MongoDB: numeric codes for SMS or GUID tokens for email links, with salted hashing, expiry checks and TTL-based cleanup.

SignedChannel.MongoDb

MongoDB session storage for SignedChannel. Provides IChannelSessionStore on top of MongoDbService, and is open for inheritance so an application can keep its own per-session state in the same document.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.3.1 165 9/29/2026
10.3.0 197 8/12/2026
10.2.1 254 8/8/2026
10.2.0 217 7/29/2026
10.1.1 128 7/17/2026
10.0.0 394 11/24/2025
6.0.0 260 11/23/2025
5.1.0 355 6/28/2025
5.0.1 496 2/12/2025
5.0.0 465 1/5/2025
4.0.0 598 7/28/2024
3.1.0 898 7/7/2024
3.0.0 208 7/6/2024
2.0.0 222 7/5/2024
1.0.0 243 6/23/2024