Schema is array of three for polymorphic modeling

My understanding when using polymorphic principles for three separate schemas would be to create a SINGLE schema that has shared values as fields and sub-documents to handle the differences. Also it would be helpful to create a field that helps inform the shape of the document. Why does the lab have an Array of schema (s) as the potential answer? This seems to be a miscommunication of the expected answer. Please help and thanks in advance.

I am trying to understand the pattern (to help out my previous post). Would you create a single schema that allows for all possibilities of in this case the three schemas being merged? Or create 3 possible schemas, with the shape field informing the application of how to proceed? Thanks in advance.

If the 3 types of documents are to be queried on common fields, you want to put them in the same collection.

This is what is happening in this lab. We ask you to create 3 schemas and provide them as an array to the validator. This is because the format we use to represent schemas in the course is a simplified version of keys/types and there is no way to present a single document with “or” clauses in it.

In a production application, you are not required to create schema representations. However, if you want to do schema validation, you will need to do so.
Schema validation is done through MQL and JSON Schema in MongoDB. JSON Schema has constructs to represent “or” conditions, optional fields, required ones, etc. It can validate any schema definition.
We decided to not use JSON Schema for the course because it is very verbose and difficult to write.
If you want to know more about schema validation with JSON Schema, please consult our docs.

Again, for this course and lab, express the 3 different possible schemas/shapes your documents would have.


Thanks Daniel, I was simply creating one “schema” with all the possibilities given the instructions. I felt that with MongoDB not insisting on any field other than _id it was a natural OR for the fields listed. The verbose flag gave away that you wished for the array. I understand that in production, if you wanted to model the document(s) in a collection that one schema would be appropriate. Thanks for the help.