Refactor Work Order Indexing to Support FerretDB Limitations #72
Labels
No labels
CI/CD
MongoDB
PostgreSQL
api
authentication
bug
documentation
duplicate
enhancement
example issue
fix
good first issue
help wanted
high-level requirement
infrastructure
invalid
low-level requirement
medium-level requirement
question
security
test
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
AndreFerreira5/starranja#72
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The current index creation script for the workOrders collection is failing on our FerretDB instance. The goal is to create a unique index on vehicleId that only applies to "active" work orders (e.g., "Draft", "InProgress", etc.).
Our initial attempts failed with MongoServerError[CannotCreateIndex]: unsupported expression:
This is a known limitation of FerretDB (and its underlying DocumentDB backend), which does not support $in or $or operators in a partial filter.
Solution
We are moving forward with Solution 2 (as documented in create_workOrder_indexes.js). This involves a schema change and a new, supported index.
This approach moves the complex logic from the database index into the application, resulting in a simple, robust, and supported index.
Action Items
Set isActive: true where status is one of ["Draft", "AwaitingApproval", "Approved", "AwaitingParts", "InProgress"].
Set isActive: false where status is one of ["Completed", "Cancelled", "Invoiced", ...].
db.workOrders.createIndex(
{ vehicleId: 1 },
{
unique: true,
partialFilterExpression: {
isActive: true
}
}
);
The updated schema:
Documentation was also updated in /docs