title: Searching for field in MongoDb when exact path is unknown
body: <p>I have a collection in Mongo where the structure is known.
  It consists of </p>
  
  <pre><code>{
      "_id" : "123456__data",
      "fields" : {
          "field1" : {
              "type" : "boolean",
              "writeAccess" : "someWriteAccess",
          },
          "field2" : {
              "type" : "integer",
              "writeAccess" : "secondWriteAccess",
          },
          "field3" : {
              "someConcretePermissionOperation" : "set",
              "writeAccess" : "thirdWriteAccess",
          }
      }
  }
  </code></pre>
  
  <p>Now I got to find all documents, and preferably, all concrete values of "someConcretePermissionOperation", while the "field1", 2, 3 can be up to the user. That is, in different documents they could have different names. The only thing I know is the constant depth - if someConcretePermissionOperation will appear it will be under <code>fields.XXX.someConcretePermissionOperation</code>, where XXX can be anything.</p>
  
  <p>Anybody got any ideas?</p>
  
  <p>Just found something close to what I am looking for:</p>
  
  <pre><code>var operationOptions = [ "push", "set", "pushUnique" ];
  db.mytable.aggregate(
     [
       { $redact:
           {
              $cond:
                 {
                   if: { $gt: [ { $size: { $setIntersection: [ "$someConcretePermissionOperation", operationOptions ] } }, 0 ] },
                   then: "$$DESCEND",
                   else: "$$PRUNE"
                 }
           }
       }
     ]
  )
  </code></pre>
  
  <p>But receiving 
  <code>uncaught exception: aggregate failed: {
      "errmsg" : "exception: The argument to $size must be an Array, but was of type: NULL",</code></p>
  
  <p>Don't exactly know yet how to write "if exists, otherwise disregard" in this aggregation query.</p>