【发布时间】:2017-12-02 05:55:17
【问题描述】:
我在我的代码中使用 Mongo PHP 库:https://github.com/mongodb/mongo-php-library/
我正在尝试使用 Mongo PHP 库中的聚合函数向 MongoDB 发送以下查询:
块引用
db.customers.aggregate(
{$match: {Country: "India", Email: {$in: [/.*@gmail.com*/,/.*@hotmail.com*/] } } },
{$group : {_id : {Email: "Email"}, "count" : {$sum : 1} } },
{$sort : {"count" : -1} }
)
此查询在 MongoDB 服务器上运行良好。但在 PHP 代码中它不起作用。
块引用
$query = array(
['$match' => ['Country' => "India",
'Email' => ['$in' => ['/.*@gmail.com*/','/.*@hotmail.com*/']]
]
],
['$group' => ['_id' => ['Email' => '$Email']
'count' => ['$sum' => 1]
]
],
['$sort' => ['count' => -1]]
);
$cursor = $this->customers->aggregate($query);
$in 数组不适用于上述通配符模式。它不显示任何错误或结果。但它适用于确切的电子邮件。如何在 $match 下的 $in 数组中提及模式
请建议我如何在 Mongo PHP 库中提交通配符模式。
【问题讨论】:
-
编辑:['_id' => ['Email' => '$Email'],