![]() |
VOOZH | about |
dotnet add package MongoDbService --version 10.0.0
NuGet\Install-Package MongoDbService -Version 10.0.0
<PackageReference Include="MongoDbService" Version="10.0.0" />
<PackageVersion Include="MongoDbService" Version="10.0.0" />Directory.Packages.props
<PackageReference Include="MongoDbService" />Project file
paket add MongoDbService --version 10.0.0
#r "nuget: MongoDbService, 10.0.0"
#:package MongoDbService@10.0.0
#addin nuget:?package=MongoDbService&version=10.0.0Install as a Cake Addin
#tool nuget:?package=MongoDbService&version=10.0.0Install as a Cake Tool
MongoDbService is an open-source C# class library that provides a wrapper around the official MongoDB.Driver, simplifying MongoDB integration in .NET applications.
ConnectionRecord collection that keeps track of compute instances connecting to your MongoDB instanceInstall the NuGet package:
dotnet add package MongoDbService
Add the following to your appsettings.json and update the values to match your MongoDB instance:
"MongoDbSettings": {
"DatabaseName": "YourDatabaseName",
"ConnectionString": "mongodb+srv://.........@gpcluster.0bulb.mongodb.net/myDatabase?retryWrites=true&w=majority"
}
Configuration Options:
DatabaseName (required): The name of your MongoDB databaseConnectionString (required): Your MongoDB connection stringInject MongoService into your classes via dependency injection:
1. Define your DTO:
using MongoDB.Bson.Serialization.Attributes;
namespace YourNameSpace
{
public sealed class Vehicle
{
[BsonId]
public required string Id { get; init; }
public required string Name { get; set; }
}
}
2. Create a handler class:
using MongoDB.Driver;
using MongoDbService;
namespace YourNameSpace
{
public sealed class VehicleHandler
{
private readonly IMongoCollection<Vehicle> _vehicleCollection;
public VehicleHandler(MongoService mongoService)
{
_vehicleCollection = mongoService.Database.GetCollection<Vehicle>(
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<DeleteResult> RemoveVehicle(string vehicleId)
{
return await _vehicleCollection.DeleteOneAsync(
Builders<Vehicle>.Filter.Eq(v => v.Id, vehicleId));
}
}
}
The project includes integration tests that require a running MongoDB instance.
localhost:27017 (or set the MONGODB_CONNECTION_STRING environment variable)dotnet test
The GitHub Actions workflow automatically runs tests against a MongoDB container on every release.
We welcome contributions! If you find a bug or have an idea for improvement, please submit an issue or pull request on GitHub.
This project is licensed under the GNU General Public License v3.0.
Happy coding! 🚀🌐📚
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 3 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 and session management. |
|
|
SMSwitch
Package Description |
|
|
MongoDbTokenManager
Package Description |
This package is not used by any popular GitHub repositories.