title: MongoDB select all where field value in a query list
body: <p>How to achieve below SQL in MongoShell?</p>
  
  <pre><code>Select TableA.* from TableA where TableA.FieldB in (select TableB.FieldValue from TableB)
  </code></pre>
  
  <p>Mongo doc gives some example of </p>
  
  <pre><code>db.inventory.find( { qty: { $in: [ 5, 15 ] } } )
  </code></pre>
  
  <p>I want that array be dynamically from another query. Is it possible?</p>
  
  <p><strong>Extending my question</strong></p>
  
  <p>I have a collection of <code>bot</code> names</p>
  
  <p><strong>bots collection</strong></p>
  
  <pre><code>{
      "_id" : ObjectId("53266697c294991f57c36e42"),
      "name" : "teoma"
  }
  </code></pre>
  
  <p>I have a collection of user traffic, in that traffic collection, I have a field <code>useragent</code></p>
  
  <p><strong>userTraffic Collection</strong></p>
  
  <pre><code>{
      "_id" : ObjectId("5325ee6efb91c0161cbe7b2c"),
      "hosttype" : "http",
      "useragent" : "Mediapartners-Google",
      "is_crawler" : false,
      "City" : "Mountain View",
      "State" : "CA",
      "Country" : "United States"
  }
  </code></pre>
  
  <p>I want to select all user traffic documents where its <code>useragent</code> contains any name of <code>bot</code> collection</p>
  
  <p>This is what I have come up with</p>
  
  <pre><code>var botArray = db.bots.find({},{name:1, _id:0}).toArray()
  
  db.Sessions.find({
      useragent: {$in: botArray}
      },{ 
          ipaddress:1
          })
  </code></pre>
  
  <p>Here i believe it is doing <strong>equals to comparison</strong>, but I want it to do <strong>like %% comparison</strong></p>
  
  <p>Once I get the result, I want to do an update to that result set as <strong>is_crawler= true</strong></p>
  
  <p>Tried something like this, isn't helpful</p>
  
  <pre><code>db.bots.find().forEach( function(myBot) {
      db.Sessions.find({
          useragent: /myBot.name/
          },{ 
              ipaddress:1
              }) 
       });
  </code></pre>
  
  <p>Another way of looping through the records, but no match found.</p>
  
  <pre><code>var bots = db.bots.find( {
      $query: {}, 
      $orderby:{
          name:1}
          });
  while( bots.hasNext()) {
      var bot = bots.next();
      //print(bot.name);
      var botName = bot.name.toLowerCase();
      print(botName);
       db.Sessions.find({
          useragent: /botName/,
          is_crawler:false
          },{ 
              start_date:1,
              ipaddress:1,
              useragent:1,
              City:1,
              State:1,
              Country:1,
              is_crawler:1,
              _id:0
          })
      }
  </code></pre>