Php 对mongo聚合结果应用$match筛选器
我创建了一个小型mongo聚合管道,我从PHP编写并运行它 聚合方法如下所示:Php 对mongo聚合结果应用$match筛选器,php,mongodb,aggregation-framework,Php,Mongodb,Aggregation Framework,我创建了一个小型mongo聚合管道,我从PHP编写并运行它 聚合方法如下所示: $results = $mongoCollection->aggregate([ ['$group' => ['_id' => ['FoobarID' => '$FoobarID'], 'count' => ['$sum' => 1]]], ['$match' => ['count' => ['$gte' => 10]]], ['$sort
$results = $mongoCollection->aggregate([
['$group' => ['_id' => ['FoobarID' => '$FoobarID'], 'count' => ['$sum' => 1]]],
['$match' => ['count' => ['$gte' => 10]]],
['$sort' => ['count' => -1]]
]);
结果的(前几个)记录如下所示:
[0] => Array
(
[_id] => Array
(
[FoobarID] => 0
)
[count] => 836
)
[1] => Array
(
[_id] => Array
(
[FoobarID] => MongoInt64 Object
(
[value] => 967298418588464438
)
)
[count] => 105
)
[2] => Array
(
[_id] => Array
(
[FoobarID] => MongoInt64 Object
(
[value] => 3397585370383372261
)
)
[count] => 101
)
...
问题1
现在我试图删除第一个聚合结果,即FoobarID=0的聚合结果。我无法让它工作
如您所见,count上的$match有效,但我无法过滤结果中的FoobarID字段
我尝试了以下方法:
['$match' => ['_id' => ['$ne' => 0]]], // also tried '0' and null
['$match' => ['FoobarID' => ['$ne' => 0]]], // also tried '0' and null
['$match' => ['_id' => ['FoobarID' => ['$ne' => 0]]]], // also tried '0' and null
我做错了什么?我错过什么了吗
问题2
如何访问MongoInt64对象中的“值”键?那有可能吗?例如,删除FoobarID MongoInt64值为96729841858848464438的聚合结果
非常感谢您的任何意见和帮助!提前非常感谢 问题1
试试这个
['$match' => ['_id.FoobarID' => ['$ne' => 0]]]
问题2
['$match' => ['_id.FoobarID' => ['$eq' => 967298418588464438]]]
问题1
试试这个
['$match' => ['_id.FoobarID' => ['$ne' => 0]]]
问题2
['$match' => ['_id.FoobarID' => ['$eq' => 967298418588464438]]]
维拉姆:非常感谢!你对问题1的回答完美地解决了问题!:-)不过,第二次我没有成功。我还尝试了不同版本的轻微更改,包括“_id.FoobarID.value”和数字als int和as string…不客气。我不是很精通php,所以不能给你一个好的答案。你能告诉我那是什么身份证吗。那是一个objectId吗?不,它不是objectId。它是一个专有ID,来自类型“MongoInt64对象”。所以它不是32位整数,而是64位整数。您使用的是64位php驱动程序,对吗?所以这应该只是一个正常的比较。恩:非常感谢!你对问题1的回答完美地解决了问题!:-)不过,第二次我没有成功。我还尝试了不同版本的轻微更改,包括“_id.FoobarID.value”和数字als int和as string…不客气。我不是很精通php,所以不能给你一个好的答案。你能告诉我那是什么身份证吗。那是一个objectId吗?不,它不是objectId。它是一个专有ID,来自类型“MongoInt64对象”。所以它不是32位整数,而是64位整数。您使用的是64位php驱动程序,对吗?所以这应该只是一个正常的比较