UmbracoExternalStorageWithMongoDB 17.0.4
dotnet add package UmbracoExternalStorageWithMongoDB --version 17.0.4
NuGet\Install-Package UmbracoExternalStorageWithMongoDB -Version 17.0.4
<PackageReference Include="UmbracoExternalStorageWithMongoDB" Version="17.0.4" />
<PackageVersion Include="UmbracoExternalStorageWithMongoDB" Version="17.0.4" />
<PackageReference Include="UmbracoExternalStorageWithMongoDB" />
paket add UmbracoExternalStorageWithMongoDB --version 17.0.4
#r "nuget: UmbracoExternalStorageWithMongoDB, 17.0.4"
#:package UmbracoExternalStorageWithMongoDB@17.0.4
#addin nuget:?package=UmbracoExternalStorageWithMongoDB&version=17.0.4
#tool nuget:?package=UmbracoExternalStorageWithMongoDB&version=17.0.4
What does this package do?
This package allows you to store your custom data in a NoSQL MongoDB database. 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.
It is built on MongoDbService and registers it with Umbraco automatically, so you can inject MongoService anywhere in your site.
Requirements
- Umbraco 17
- .NET 10
Setup procedure
- Set up a MongoDB server either locally on your laptop or you can use the MongoDB free hosting plan to create an instance on AWS, GCP or Azure.
- Update
appsettings.jsonfile with the connection string to the above database
{
"MongoDbSettings": {
"ConnectionString": "<mandatory> mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority",
"DatabaseName": "<optional, defaults to Untitled-MongoDbService>",
"ConnectionRecordRetentionDays": 30
}
}
Keep the connection string out of source control: for local development use user secrets (dotnet user-secrets set "MongoDbSettings:ConnectionString" "<connection string>"), and in hosted environments set the MongoDbSettings__ConnectionString environment variable.
If ConnectionString is missing, an ArgumentException is thrown the first time MongoService is resolved.
3. Install this package
dotnet add package UmbracoExternalStorageWithMongoDB
Sample code
using MongoDB.Driver;
using MongoDbService;
public sealed class VehicleHandler
{
private readonly IMongoCollection<Vehicle> _vehicleCollection;
public VehicleHandler(MongoService mongoService)
{
_vehicleCollection = mongoService.Database.GetCollection<Vehicle>("YourCollectionName");
}
}
Register your own classes with Umbraco, for example in a composer:
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
public sealed class VehicleComposer : IComposer
{
public void Compose(IUmbracoBuilder builder) => builder.Services.AddSingleton<VehicleHandler>();
}
For more examples on how to Insert, Modify your data, check the MongoDbService documentation and the MongoDB official documentation: https://www.mongodb.com/docs/drivers/csharp/current/quick-reference/
Upgrading from version 13
Version 17 is a breaking change:
- The configuration section is renamed from
MongoDbCredentialstoMongoDbSettings, and the database name now comes fromMongoDbSettings:DatabaseName. CertificateFilePathWithNameandCertificatePasswordare no longer supported.- The static
MongoDBClientConnection.GetDatabase("...")is replaced by injectingMongoServiceand usingmongoService.Database. - MongoDbService writes a
ConnectionRecorddocument each time the site connects. These are removed afterConnectionRecordRetentionDays(default 30).
Want to sponsor?
This is a free package, but if you want to sponsor my open source work, here is my GitHub profile
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- MongoDbService (>= 10.3.1)
- Umbraco.Cms.Core (>= 17.0.0 && < 18.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.