Multiple document schema in same collection mapping to POJO

I have multiple excel templates with versions. Between every template version the structure of data varies i.e. columns/rows, different pages… etc.
For each excel template version I’ve created its own document schema. I want to store all the documents in the same collection regardless of the excel template version (as there are too many versions for multiple collections).
Question is, how do I map different schemas into a single POJO. As the structure changes between each template version I’m ending up creating a unique POJO class for each schema!!
If I need to create a POJO for each excel template version, and my application code needs to change every time a schema change is introduced (like addition of a key/field) what is the advantage of using mongoDB vs RDBMS in my case? mongo promises no fixed schemas but practically I need to separate schemas to new collections due to POJO mapping?? Are there any dynamic mapping strategies I’ve missed to avoid application update every time a new schema is added to the collection?

Thanks in advance.

I solve this with inheritance. I am not sure, how you use MongoDB, but in dotnet you can create an abstract class for all your versions, and inherit your specific version from this parent class. Like:

[BsonKnownTypes(typeof(ExcelTemplate1), typeof(ExcelTemplate2))]
public abstract class ExcelTemplateBase { ... }

public class ExcelTemplate1 :  ExcelTemplateBase { ... }

public class ExcelTemplate2 :  ExcelTemplateBase { ... }

Then you can create the collection for the abstract ExcelTemplateBase class.

You also can also avoid defining the known types as attributes, you can do it by creating the ClassMapping from code.

See also: https://www.mongodb.com/docs/drivers/csharp/current/fundamentals/serialization/polymorphic-objects/

I guess in Java there should be a similar solution.