Advanced

Performance

Pitfalls and tips for optimizing Mongalayer performance.

Access control overhead

Mongalayer is not intended for high-performance write and complex query scenarios. Both read and write operations incur overhead due to access control checks.

insert operations are the least affected, as they check the inserted document itself against the access filters without needing to read from the database first. Unless one access definition specifies a alternative collection for role resolution, in that case an additional read is performed on that insert operation and thus incurs more overhead.

update and delete operations perform an additional read to resolve access roles before executing the actual write.

find and aggregate operations are transformed and also incur some overhead. They are rewritten to aggregations to include the access filters, which can lead to more complex queries and thus slower execution times, especially if there are many access definitions or complex filters.

To optimize performance, make sure to have proper indexes on the fields used in access filters. And keep your access definitions as simple and few as possible by defining a good application model.
If you need maximum write throughput without access control, use the MongoDB driver directly via a custom implementation.
Copyright © 2026