title: How do i check with a MongoDB query if a property in an object exists?
body: <p>I'm building a simple query for my MongoDB Collection. The model looks like this:</p>
  
  <pre><code>{
      a: [],
      user: {
          email: String,
          name: String,
          surname: String
      }
  }
  </code></pre>
  
  <p>What I need to get from the query are all the documents that have 'a' as non-empty array and the 'user.email' set. My query is:</p>
  
  <pre><code>Document.find({
          a: {
              $exists: true,
              $not: {
                  $size: 0
              }
          },
          user: {
              $exists: true,
              'email': {
                  $exists: true
              }
          }
      })
  </code></pre>
  
  <p>The problem is when i perform the query, my server returns a 500 Error saying:</p>
  
  <pre><code>{
      "error": {
          "name": "MongoError",
          "message": "unknown operator: email",
          "waitedMS": 0,
          "ok": 0,
          "errmsg": "unknown operator: email",
          "code": 2
      }
  }
  </code></pre>
  
  <p>Where am I going wrong? Can anyone help me with this?
  Thank you!</p>