title: How to set an object as nullable in Javascript (NodeJS)
body: <p>I keep getting an error: <code>TypeError: Cannot read property 'doors' of null</code>. I want to be able to set <code>doors</code> to be nullable, as to be able to avoid this error and simply hit the error response and return 404. However, I am not sure how to do this?</p>
  <p>Here is my code:</p>
  <pre><code>Data.findOne({
          '_id':'6182544c20d538aefe49def0',
          'doors.id':doorId  
      }, {
          'doors.$':1
      }, function(err, data) {
          if (err) {
              res.status(404).send('No Matching Door Found')
          } else if (data.doors[0].status === 'open') {
              res.status(401).send('Door already unlocked')
          } else {
              res.status(200)
          }
      })
  </code></pre>
  <p>The error is hit on the third line, where It cannot find a doors object where the ID is equal to <code>doorId</code>.</p>
  <p>I have tried setting <code>doors.id</code> to <code>!doors.id</code>, however, this then kept hitting the 404 regardless of what was being entered.
  Any help is appreciated, thank you.</p>