我想知道是否可以像使用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