Chapter 4: Patterns (Part 2) Lab: Apply the Polymorphic Pattern

Chapter 4: Patterns (Part 2)

Lab: Apply the Polymorphic Pattern

Problem:

User Story

Our company has been selling books online for many years.

Recently, we decided to expand and acquired the rights to sell the books as ebooks and as audiobooks.

I am new to this are … I do not understand what mistake I’m making … this code is not working

{
  "_id": "<objectId>",
  "product_id": "<int>",
  "description": "<string>",
 "authors": ["<string>"],
 
"format" : {


     "book" : {

            "title": "<string>",
            
            "publisher": "<string>",
            "language": "<string>",
            "pages": "<int>",
            "catalogues": {
            "isbn10": "<string>",
            "isbn13": "<string>"
            }
            } ,

    "ebook" : {

            "title": "<string>",
         
            "publisher": "<string>",
            "language": "<string>",
            "eformats": {
                    "epub": {
                      "pages": "<int>"
                            },
                    "pdf":  {
                      "pages": "<int>"
                            }
                    },
            "isbn10": "<string>"
            }, 
     "audiobook" : {
            "title": "<string>",    
            "narrator": "<string>",
            "publisher": "<string>",
            "language": "<string>",
            "length_minutes": "<int>"
        }
    }
}

Hi @Hariom_Upadhyay

Can you open a separate thread to deal with your question/issue as it will help us better focus and answer it?

I think the discussion in Apply the Polymorphic Pattern Lab - #13 by steevej is very relevant. I’d suggest breaking the three different types of content into separate documents as suggested to you in that thread. You have only one document in your answer and this is not the optimal solution. Three different documents each holding only the relevant information for that type of content is what your schema should reflect.

Hope this helps and if you have any further questions, please open a new thread to continue the discussion.

Kindest regards,
Eoin