166 CommandNotSupportedOnView: CommandNotSupportedOnView
MongoDBWhat does it mean?
The command is not supported on a view. MongoDB views are read-only and accept only certain read operations; writes or unsupported commands are rejected.
Why does it happen?
Write operations such as insert/update/delete, or certain commands not supported on views (e.g. some text/geo operations, direct index creation), were attempted on a view. Seen when the application tries to write to a view thinking it is a collection.
How to fix it
Perform writes on the underlying (source) collection the view is based on; views are for reads only. Verify whether the command is supported on views and use supported read/aggregation operations. If you need a writable structure, design a materialized collection ($merge/$out) instead of a view.