title: complex query to mongodb database $eq ObjectID
body: <p>Hi Can someone tell me why I cant $eq author with objectId?</p>
  
  <pre><code>db.boards.aggregate(
    [
      {
        $project: {
          "boardcards": {
            $reduce: {
              input: "$lists.cards",
              initialValue: [ ],
              in: { $concatArrays: [ "$$value", {
              $filter: {
                 input: "$$this",
                 as: "result",
                 cond: { "$eq": [
                        "$$result.Author",
                         ObjectId("59df60fb6fad6224f4f9f22d")                    
                     ] 
                     }
              }
           } 
           ] 
           }
            }
          }
        }
      }
    ]
  )
  </code></pre>
  
  <p>If I change ObjectId("59df60fb6fad6224f4f9f22d") for "dada" and in $lists.cards is position like :</p>
  
  <pre><code>    "cards" : [ 
          {
              "name" : "1"
          }, 
          {
              "name" : "2"
          }, 
          {
              "name" : "3",
              "Author" : "dada"
          }
      ]
  }, 
  </code></pre>
  
  <p>The query will find the result, but if i Change for ObjectID where I have:</p>
  
  <pre><code> {
              "list" : "6",
              "cards" : [ 
                  {
                      "name" : "1"
                  }, 
                  {
                      "name" : "2"
                  }, 
                  {
                      "name" : "3",
                      "Author" : [ObjectId("59df60fb6fad6224f4f9f22d")]
                  }
              ]
          }
  </code></pre>
  
  <p>Can someone tell me how to fix that,because i cant equall with objectid</p>
  
  <p>Its can be by that I dont have set in model Object id??</p>
  
  <pre><code>var mongoose = require('mongoose');
  </code></pre>
  
  <p>var Schema = mongoose.Schema;</p>
  
  <pre><code>var BoardSchema = new Schema({
    name: { type: String, maxlength: 20 },
    lists : { type: Array },
    users : [{ type : Schema.Types.ObjectId, ref: 'User' }],
  
  
  });
  
  module.exports = mongoose.model('Board', BoardSchema);
  </code></pre>
  
  <p><strong>EDIT</strong>
  I need to make search given id in array If I have:</p>
  
  <pre><code> {
              "list" : "6",
              "cards" : [ 
                  {
                      "name" : "1"
                  }, 
                  {
                      "name" : "2"
                  }, 
                  {
                      "name" : "3",
                      "Author" : [ObjectId("59df60fb6fad6224f4f9f22d"), ObjectId("59df60fb6fad6224f4f9f22d"), ObjectId("59df60fb6fad6224f4f9f22d")                                  ]
                  }
              ]
          }
  </code></pre>
  
  <p>I did like u said:</p>
  
  <pre><code>    db.boards.aggregate(
    [
      {
        $project: {
          "boardcards": {
            $reduce: {
              input: "$lists.cards",
              initialValue: [ ],
              in: { $concatArrays: [ "$$value", {
              $filter: {
                 input: "$$this",
                 as: "result",
                     cond : { "$in": [ "$$result.Author", array ]}
              }
           } 
           ] 
           }
            }
          }
        }
      },
      {
      "$unwind": "$boardcards"
    } 
    ]
  )
  </code></pre>
  
  <p>and is error, array is not defined </p>