带$and和$nin的perl MongoDB查询

带$and和$nin的perl MongoDB查询,perl,mongodb,Perl,Mongodb,我试图使用MongoDB Perl驱动程序对具有这种文档结构的集合进行查询: { "_id" : ObjectId("519fcfa59fb9d97874000001"), "variant" : { "alt" : "T", "ref" : "C", "chr" : NumberLong(1), "pos" : NumberLong(13302), "rsID" : "rs180734498"

我试图使用MongoDB Perl驱动程序对具有这种文档结构的集合进行查询:

{
    "_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)
        ]
    }
}
下面是我糟糕的perl代码片段:

  my $hom_count = $exomevars->count({
    '$and' => [ {
          "variant.chr" => $chr,
          "variant.pos" => $pos,
          "variant.ref" => $ref,
          "variant.alt" => $alt,
          "genotype.GT" => qr/1\/1/,
          "sample.tags" => { '$nin' => \@these_tags }
          } ]
         });
我的收藏确实在这些字段上建立了索引-

{
    "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"
}
…但我的脚本挂起,没有查询发生。我敢肯定是查询中的$nin/sample.tags部分是我的问题,如果我取出\@this_标记并硬编码一些文本,它仍然挂起而没有查询

“sample.tags”=>{'$nin'=>[“stuff”,“things”]},

还确保我的@Thes_标记数组与Data::Dumper一起工作-看起来我做对了

print Dumper \@these_tags;
    $VAR1 = [
              'Please',
              'help',
              'stackoverflow',
              'friends'
            ];
这不是
qr/1\/1/
-我以前使用过这个查询,它工作正常。作为一个示例,这里是脚本的早期版本,我仅尝试基于单个字符串排除,此查询运行良好:

  my $hom_count = $exomevars->count({
      '$and' => [ {
          "variant.chr" => $chr,
          "variant.pos" => $pos,
          "variant.ref" => $ref,
          "variant.alt" => $alt,
          "genotype.GT" => qr/1\/1/,
          "sample.ID" => { '$ne' => $this_sample }
          } ]
         });
只有当我将
sample.tags
数组添加到集合中,现在才尝试
$nin
操作符时,小家伙,我迷路了

我试着把所有的$and条款都去掉了,但还是什么都没有。我在4节点碎片设置和MongoDB-0.700.0 perl驱动程序上使用MongoDB v2.4.3

我哪里出了问题,有什么指点吗?我应该提供的任何其他信息


非常感谢

我没有尝试完整的查询,但是
$nin
肯定没有问题。使用您的示例文档,我可以运行以下操作:

perl -MMongoDB -E 'say MongoDB::MongoClient->new->get_database( "so" )
->get_collection("vars")->count( { "sample.tags" => { "\$nin" => [ "hiseq", "foo" ] } } )'

0

perl -MMongoDB -E 'say MongoDB::MongoClient->new->get_database( "so" )
->get_collection("vars")->count( { "sample.tags" => { "\$nin" => [ "narf", "foo" ] } } )'

1
如果您尝试在shell中运行此查询,并在?藏品有多大

编辑:

日志中的这一点很有趣:

$nin: [ [ "Please", "Help", "stackoverflow", "friends" ] ]
您有一个包含数组的数组,但它应该是:

$nin: [ "Please", "Help", "stackoverflow", "friends" ]

你确定你的数组有你所想的吗?

它是一个318534850个文档的集合。。。count在shell中工作,explain是巨大的,所以它在pastebin上,看起来索引工作正常。当您从Perl运行查询时,
mongod
日志中有什么有趣的内容吗?这是从Perl尝试时的一个碎片中得到的日志:@caddymob,用您的日志中的一些见解更新了答案。哎呀,这是我的错-我尝试了
“sample.tags”=>{'$nin'=>[\@this\u tags]}
,这就是输出。因此,让我们在没有最初发布的括号的情况下重试。。。