我想知道是否可以像使用MongoDB :: Collection模块一样从mongo shell中使用“in”运算符。我尝试了很多东西,但还没有得到我期待的结果。我已经检查了文档和其他帖子在stackoverflow,但似乎无法找到任何具体的这个,除非我忽略了一些东西。
http://docs.mongodb.org/manual/reference/operator/query/in/
我通过蒙戈shell中运行计数查询
mongo:PRIMARY> db.getCollection("Results").count({ TestClass : "TestClass", TestMethod : { $in: ["method1" , "method2", "method3"] } })
181605
我曾尝试将列表传递数组或哈希裁判或建设前期A这几个不同的方法串...
my $count = $mongo->{collection}->count({
'TimeStamp' => { '$gt' => $ft, '$lt' => $tt },
'TestClass' => $TestClass,
'TestMethod' => { '$in' => [$whitelist->methods] },
'Result' => $result
});
哪里倾销$whitelist->methods
是
$VAR1 = {
'method1' => 1,
'method2' => 1,
'method3' => 1
};
我已经看到高和低的答案,没有人知道如果驱动程序目前能够使用$ in这样的运算符?通过从先前查询返回的方法循环并添加结果将需要更多的代码。
我看到关于$ in操作符的唯一其他堆栈溢出帖子是$in mongoDB operator with _id in perl建议使用http://api.mongodb.org/perl/current/MongoDB/OID.html,但不要认为这与我的示例相关,因为看起来更像是使用ID。
任何帮助或讨论将不胜感激。
您的$ whitelist->方法是一个hashref,而不是一个数组。当你写'[keys%{$ whitelist-> methods}]'时,会发生什么呢? – raina77ow
真棒,似乎工作,并产生一个结果!感谢您的帮助:-) – user2924781
你想我发表这个答案,所以你可以接受它吗? ) – raina77ow