title: Mongoose Schema, Storing an object which may or may not have properties
body: <p>I am querying an API to get results for tv episodes and saving them to my mongodb collection. The code is as follows:</p>
  
  <pre><code>let episode = JSON.parse(response);
                          for(let j=0;j&lt;episode.length;j++){
                            let newEpisode = {
                              title: episode[j].name,
                              number: episode[j].number,
                              season: episode[j].season,
                              date: episode[j].airdate,
                              duration: episode[j].runtime,
                              poster: episode[j].image.medium,
                              description: episode[j].summary
                            }
  
                            show.episodes.unshift(newEpisode);
                          }
                          show.save()
  </code></pre>
  
  <p>The problem is with the poster variable. The API either returns an object with two strings: </p>
  
  <pre><code>poster:
     medium: 'url-to-image'
     original: 'url-to-image'
  </code></pre>
  
  <p>or it returns poster with the value of null. </p>
  
  <p>Is there a way to save poster in the collection so that it saves either both strings if they are present, or null if they are not?
  It won't let me cast it to an array, and if I try to save one of the properties like in the above code, I get the error 'cannot read property 'medium' of null'.</p>