title: Two queries on different collections - MongoDB
body: <p>I have two collections in MongoDB. The first contains information about some football coaches and the second contains data about teams.
  For example, this is a document of coach collection:</p>
  
  <pre><code> {
           "_id" : ObjectId("556caaac9262ab4f14165fca"),
           "name" : "Luis",
           "surname" : "Enrique Martinez Garcia",
           "age" : 45,
           "date_Of_birth" : {
                   "day" : 8,
                   "month" : 5,
                   "year" : 1970
           },
           "place_Of_birth" : "Gijòn",
           "nationality" : "Spanish",
           "preferred_formation" : "4-3-3 off",
           "coached_Team" : [
                   {
                           "team_id" : "Bar.43",
                           "in_charge" : {
                                   "from" : "01/july/2014"
                           },
                           "matches" : 59
                   },
                   {
                           "team_id" : "Cel.00",
                           "in_charge" : {
                                   "from" : "9/june/2013",
                                   "to" : "30/june/2014"
                           },
                           "matches" : 40
                   },
                   {
                           "team_id" : "Rom.01",
                           "in_charge" : {
                                   "from" : "7/june/2011",
                                   "to" : "10/may/2012"
                           },
                           "matches" : 41
                   }
  </code></pre>
  
  <p>Here is a document of team collection:</p>
  
  <pre><code>   {
             "_id" : "Bar.43",
             "official_name" : "Futbol Club Barcelona",
             "country" : "Spain",
             "started_by" : {
                     "day" : 28,
                     "month" : 11,
                     "year" : 1899
             },
             "stadium" : {
                     "name" : "Camp Nou",
                     "capacity" : 99354
             },
             "palmarès" : {
                     "La Liga" : 23,
                     "Copa del Rey" : 27,
                     "Supercopa de Espana" : 11,
                     "UEFA Champions League" : 4,
                     "UEFA Cup Winners Cup" : 4,
                     "UEFA Super Cup" : 4,
                     "FIFA Club World cup" : 2
             },
             "uniform" : "blue and dark red"
     }
  </code></pre>
  
  <p>Well, I know mongo does not support join between collections. 
  Now suppose I saved the return of a query on team collection in an array called x.
  For example:</p>
  
  <pre><code>var x = db.team.find({_id:"Bar.43"}).toArray()
  </code></pre>
  
  <p>Now I want to use this array x to query coach collection and find coaches that coached the team with that id. 
  I tried in some ways, but they don't work:</p>
  
  <pre><code>[1]
  
  db.coach.aggregate([{$unwind:"$coached_Team"},{$match:{"coached_Team.team_id:"x[0]._id"}}])
  
  [2]
  db.team.find({"x[0]._id":{$in:coached_Team}})
  </code></pre>
  
  <p>P.S. I looked for similar questions in the forum, and the answers don't reply to mine. <br>
  <a href="https://stackoverflow.com/questions/10414402/mongodb-querying-multiple-collections-with-two-queries">This</a>, for example, does not work.</p>