title: MongoDB query with perl with $and and $nin
body: <p>I am attempting to use the MongoDB Perl driver to do a query on a collection with this kind of document structure:</p>
  
  <pre><code>{
      "_id" : ObjectId("519fcfa59fb9d97874000001"),
      "variant" : {
          "alt" : "T",
          "ref" : "C",
          "chr" : NumberLong(1),
          "pos" : NumberLong(13302),
          "rsID" : "rs180734498"
      },
      "genotype" : {
          "GT" : "0/0"
      },
      "sample" : {
          "ID" : NumberLong(8751),
          "tags" : [
              "hiseq",
              "exome",
              NumberLong(8751)
          ]
      }
  }
  </code></pre>
  
  <p>Here is the snippet of my BAD perl code:</p>
  
  <pre><code>  my $hom_count = $exomevars-&gt;count({
      '$and' =&gt; [ {
            "variant.chr" =&gt; $chr,
            "variant.pos" =&gt; $pos,
            "variant.ref" =&gt; $ref,
            "variant.alt" =&gt; $alt,
            "genotype.GT" =&gt; qr/1\/1/,
            "sample.tags" =&gt; { '$nin' =&gt; \@these_tags }
            } ]
           });
  </code></pre>
  
  <p>My collection is indeed indexed on these fields - </p>
  
  <pre><code>{
      "v" : 1,
      "key" : {
          "variant.chr" : 1,
          "variant.pos" : 1,
          "variant.ref" : 1,
          "variant.alt" : 1,
          "genotype.GT" : 1,
          "sample.tags" : 1
      },
      "ns" : "vars.exomevars",
      "name" : "variant.chr_1_variant.pos_1_variant.ref_1_variant.alt_1_genotype.GT_1_sample.tags_1"
  }
  </code></pre>
  
  <p>...but my script hangs and no query happens. I am pretty sure it is the $nin/sample.tags part of the query that is my problem, if I take out my \@these_tags and hard code some text like this, it still hangs without a query...</p>
  
  <p><code>"sample.tags" =&gt; { '$nin' =&gt; ["stuff","things"] },</code></p>
  
  <p>Also made sure my @these_tags array is working with Data::Dumper - seems I'm getting it right...</p>
  
  <pre><code>print Dumper \@these_tags;
      $VAR1 = [
                'Please',
                'help',
                'stackoverflow',
                'friends'
              ];
  </code></pre>
  
  <p>It's not the <code>qr/1\/1/</code> - I've used this query before and it works fine. As an example, here is an earlier version of the script where I was only trying to exclude based on a single string, this query works beautifully:</p>
  
  <pre><code>  my $hom_count = $exomevars-&gt;count({
        '$and' =&gt; [ {
            "variant.chr" =&gt; $chr,
            "variant.pos" =&gt; $pos,
            "variant.ref" =&gt; $ref,
            "variant.alt" =&gt; $alt,
            "genotype.GT" =&gt; qr/1\/1/,
            "sample.ID" =&gt; { '$ne' =&gt; $this_sample }
            } ]
           });
  </code></pre>
  
  <p>It's only when I added the <code>sample.tags</code> array to the collection and now try the <code>$nin</code> operator, whelp, I'm lost...</p>
  
  <p>I've tried taking out the whole $and clause, still nothing. I'm using MongoDB v2.4.3 on a 4-node shard setup and the MongoDB-0.700.0 perl driver.</p>
  
  <p>Any pointers on where I've gone wrong? Any additional info I should provide? </p>
  
  <p>Many thanks in advance!!</p>