title: Boolean aggreagte in MongoDB array
body: <p>I have a JSON document as shown below</p>
  
  <pre><code>[
  {a: "v1",b: "v2",c: "v3",d: [{k1: true},{k2: true},{k3: false}]},
  {a: "v1",b: "v2",c: "v7",d: [{k1: false},{k2: true},{k3: false}]},
  {a: "v8",b: "v9",c: "v3",d: [{k1: false},{k2: true},{k3: true},{k4: false}]},
  {a: "v5",b: "v2",c: "v10",d: [{k1: false},{k2: true},{k3: false}]}
  ]
  </code></pre>
  
  <p>I want to write query as shown below:</p>
  
  <pre><code>select d from the above docs
  where a = v1
  and b = v2
  </code></pre>
  
  <p>The expected result will be following two documents:</p>
  
  <pre><code>{a: "v1",b: "v2",c: "v3",d: [{k1: true},{k2: true},{k3: false}]},
  {a: "v1",b: "v2",c: "v7",d: [{k1: false},{k2: true},{k3: false}]}
  </code></pre>
  
  <p>So far, its easy. The query below will give you the result:</p>
  
  <pre><code>db.audit.find({a:"v1", b:"v2"},{d:1,_id:0}).pretty()
  </code></pre>
  
  <p>Question - </p>
  
  <p>Now the requirement is to do Boolean operation among the retrieved documents.
  "OR" Boolean operation should be on the values of respective keys (k1, k2, k3, etc.) found in the sub-documents of array elements of "d" key.</p>
  
  <p>Wherever a key is not present, assume it false.</p>
  
  <p>Is there to do this in MongoDB?</p>
  
  <p>Its easy to programatically by assigning d to variable and then compare, but I am trying to find if MongoDB can do it directly.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Thanks
  Auro</p>