Applying Polymorphic pattern

Hello community.
I am stuck in this lab of polymorphic pattern.
With my limited knowledge i have tried modifying the schema according to the instructions given.

The task i have to complete goes like this:

  • Across all documents, we will use a new field called format that will have a value of book, ebook, or audiobook.
  • Across all documents, we will have a field called product_id that will accept an integer as its value.
  • The field description should be unified across all documents.
  • The field authors should be unified across all documents.

Due to my limited understanding of the topic, i don’t where i am making the mistake.

When i validate it shows following error’

Processing document: 1

… against solution: 1
The document fails validation.

Processing document: 2

… against solution: 2
The document passes validation

Processing document: 3

… against solution: 3
The document passes validation

At least one of your solutions is not passing validation.

Plz help.

it is not easy to spot errors within a JSON field just by eye.

change the order of your fields so that common fields are together at the top half and format specific ones at the bottom half.

  • make sure all 3 formats have exact same common fields by copy-pasting (manual typing is prone to typos).
  • make sure all format-specific fields are there with their respective types.

Hi Yilmaz,

I have the same problem, I don’t understand what is wrong on my schema ? Can I have some Help ?

  "_id": "<objectId>",
  "product_id": "<int>",
  "title": "<string>",
  "description": "<string>",
  "authors": ["<string>"],
  "publisher": "<string>",
  "language": "<string>",
  "format" : 
  [{"book" : {
  "pages": "<int>",
  "catalogues": {
		"isbn10": "<string>",
		"isbn13": "<string>"
  {"ebook" : {
	  "eformats": {
			"epub": {
			  "pages": "<int>"
			"pdf": {
			  "pages": "<int>"
	"isbn10": "<string>"
  {"audiobook" : {
	  "narrator": "<string>",
	  "length_minutes": "<int>"

Hi @Rick_TarHack
You misunderstood how you should combine schemas. you combined formats in an array “inside” a single schema { other:properties, ... , format:[book, ebook, audiobook] } . Doing so you happen to define a single document to have a “format” array field, not 3 different document schemas.

Instead, you need 3 independent schemas in an array at the top level and then have all properties in those 3 schemas.

[ {book_schema}, {ebook_schema}, {audiobook_schema} ]

my proposed way above to combine properties is for each of the 3 schemas separately. these 3 will share some common properties and then have their own.

1 Like

Thank Yilmaz,

I just validated Lab ! :grinning: