elsa-workflows/elsa-core · error · InvalidOperationException
MongoDB physicalization supports dedicated document…
Error message
MongoDB physicalization supports dedicated document collections only.
What it means
MongoDbPhysicalizationPlanner.Plan maps a persistence schema to MongoDB physical objects, but it only implements the DedicatedDocumentCollection strategy where each storage unit becomes its own collection. Passing any other PhysicalizationTarget throws InvalidOperationException during planning.
Solutions
- Set policy.Target = PhysicalizationTarget.DedicatedDocumentCollection in your StoragePhysicalizationPolicy when using the MongoDB provider.
- If another target is required, use the persistence provider that implements it instead of the MongoDB planner.
- Centralize policy construction per provider so the relational and MongoDB configurations are not shared.
Example fix
// before
var policy = new StoragePhysicalizationPolicy { StorageUnit = "orders", Target = PhysicalizationTarget.SharedTable };
var plan = planner.Plan(schema, policy); // throws
// after
var policy = new StoragePhysicalizationPolicy { StorageUnit = "orders", Target = PhysicalizationTarget.DedicatedDocumentCollection };
var plan = planner.Plan(schema, policy); Defensive patterns
Strategy: type-guard
Validate before calling
if (policy.Target != PhysicalizationTarget.DedicatedDocumentCollection)
throw new NotSupportedException($"MongoDB provider only supports DedicatedDocumentCollection, got {policy.Target}."); Type guard
static bool IsMongoCompatible(StoragePhysicalizationPolicy p) => p.Target == PhysicalizationTarget.DedicatedDocumentCollection;
Try / catch
try
{
var plan = planner.Plan(schema, policy);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("physicalization"))
{
logger.LogError(ex, "Incompatible physicalization target {Target}", policy.Target);
throw;
} Prevention
- Configure PhysicalizationTarget per persistence provider; do not share policy objects between relational and MongoDB setups.
- Only ever set PhysicalizationTarget.DedicatedDocumentCollection when using the MongoDB provider.
- Assert the target in startup configuration tests so misconfiguration fails fast.
When it happens
Trigger: Calling Plan with a StoragePhysicalizationPolicy whose Target is anything other than PhysicalizationTarget.DedicatedDocumentCollection (e.g. a shared-table or embedded strategy).
Common situations: Configuring the physicalization policy copied from a relational-provider setup; a shared policy object defaulting to a non-Mongo target; switching persistence providers without updating the target enum.
Related errors
- SQLite physicalization supports dedicated relational tables…
- A configuration key is required.
- A configured default role no longer exists.
- A workflow definition or artifact-relative path is required.
- Adapter ' ' does not provide a settings migration from…
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/a705d2efa451f6f9.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Persistence.VNext.MongoDb/Physicalization/MongoDbPhysicalizationPlanner.cs:11
using Elsa.Persistence.VNext;
using Elsa.Persistence.VNext.Physicalization;
namespace Elsa.Persistence.VNext.MongoDb.Physicalization;
public class MongoDbPhysicalizationPlanner : IPhysicalizationPlanner
{
public PhysicalizationPlan Plan(PersistenceSchema schema, StoragePhysicalizationPolicy policy)
{
if (policy.Target != PhysicalizationTarget.DedicatedDocumentCollection)
throw new InvalidOperationException("MongoDB physicalization supports dedicated document collections only.");
PhysicalizationPolicyValidator.GetStorageUnit(schema, policy);
var collectionName = NormalizeName(policy.PhysicalName ?? policy.StorageUnit);
var operations = new List<PhysicalizationOperation>
{
new("CreateCollection", $"Create dedicated MongoDB collection {collectionName} for {policy.StorageUnit}.")
};
foreach (var index in policy.Indexes)
{
var fields = string.Join(",", index.Fields.Select(field => $"Data.{field}:1"));
var uniqueness = index.IsUnique ? "unique" : "non-unique";
operations.Add(new(
"CreateIndex",
$"Create {uniqueness} MongoDB index {index.Name} on {collectionName} ({fields})."));
}
View on GitHub (pinned to fe9217bdfa)