Razory.MongoDB
2.1.1
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Razory.MongoDB --version 2.1.1
NuGet\Install-Package Razory.MongoDB -Version 2.1.1
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="Razory.MongoDB" Version="2.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Razory.MongoDB" Version="2.1.1" />
<PackageReference Include="Razory.MongoDB" />
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 Razory.MongoDB --version 2.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Razory.MongoDB, 2.1.1"
#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 Razory.MongoDB@2.1.1
#: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=Razory.MongoDB&version=2.1.1
#tool nuget:?package=Razory.MongoDB&version=2.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Razory.MongoDB
MongoDB provider for Razory. Implements IRepository and IQueryObject<T> using the official MongoDB .NET Driver.
Installation
dotnet add package Razory.MongoDB
Setup
1. Implement IMongoEntityConfiguration<T> for each entity
public class ProductConfiguration : IMongoEntityConfiguration<Product>
{
public string Name => "products"; // collection name
public void ConfigureCollection(IMongoCollection<Product> collection)
{
// optional: create indexes, TTLs, etc.
collection.Indexes.CreateOne(
new CreateIndexModel<Product>(
Builders<Product>.IndexKeys.Ascending(p => p.Category)));
}
}
2. Implement IDatabaseConfiguration
public class MyMongoDatabaseConfiguration : IDatabaseConfiguration
{
private readonly List<IEntityConfiguration> configurations =
[
new ProductConfiguration(),
new OrderConfiguration(),
];
public string ConnectionString => "mongodb://localhost:27017";
public string GetDatabaseName<T>() where T : EntityBase => "my_database";
public IEntityConfiguration<T> GetEntityConfiguration<T>() where T : EntityBase =>
configurations.OfType<IEntityConfiguration<T>>().Single();
public IEnumerable<IEntityConfiguration> GetAllEntityConfigurations() => configurations;
}
3. Register
builder.Services.ConfigureRazoryMongoDB(new MyMongoDatabaseConfiguration());
This registers:
IRepository→MongoRepositoryIQueryObject<T>→MongoQueryObject<T>- All internal commands (
ICreateDocumentCommand,IUpdateDocumentCommand, etc.) ICollectionResolver,IDatabaseResolver
Usage
Inject IRepository for CRUD and IQueryObject<T> for queries:
public class ProductService(IRepository repository, IQueryObject<Product> query)
{
public Task<Product> GetByIdAsync(Guid id) =>
repository.GetAsync<Product>(id);
public Task InsertAsync(Product product) =>
repository.InsertAsync(product);
public Task UpsertAsync(Product product) =>
repository.UpsertAsync(p => p.Id == product.Id, product);
public Task<IEnumerable<Product>> GetActiveByCategoryAsync(string category) =>
query
.FilterBy<ProductFilter>(f => f.ActiveOnly().WithCategory(category))
.SortAscending(p => p.Name)
.Query()
.GetAllAsync();
public Task<IEnumerable<Product>> GetPageAsync(int page, int size) =>
query
.FilterBy(p => p.IsActive)
.Query()
.Skip((page - 1) * size)
.Limit(size)
.GetAllAsync();
}
MongoDB-specific result features
Query() returns IMongoQueryObjectResult<T> and Aggregate() returns IMongoQueryObjectAggregateResult<T>. These extend the base interfaces with MongoDB-native operations:
Native projection via IMongoQueryObjectProjectionDefinition<TSource, TDestination>
public class ProductSummaryProjection : IMongoQueryObjectProjectionDefinition<Product, ProductSummary>
{
public ProjectionDefinition<Product, ProductSummary> Definition(
ProjectionDefinitionBuilder<Product> builder) =>
builder.Expression(p => new ProductSummary
{
Id = p.Id,
Name = p.Name,
});
}
var result = (IMongoQueryObjectResult<Product>)query.Query();
var summaries = await result.Project(new ProductSummaryProjection()).GetAllAsync();
Aggregate Unwind
var result = (IMongoQueryObjectAggregateResult<Order>)query.Aggregate();
var items = await result.Unwind<OrderItem>("Items").GetAllAsync();
Repository
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- MongoDB.Driver (>= 3.6.0)
- Razory (>= 2.1.1)
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 |
|---|