[英]MongoDB & PHP - How do I exclude results from a date range delimited query?
Long time peruser, first time question asker ... 长时间的用户,第一次提问者...
Using PHP to query our MongoDB page visit log, I would like to get a set of records between two time periods, but exclude results that have a certain userAgent. 我想使用PHP查询我们的MongoDB页面访问日志,我希望获得两个时间段之间的一组记录,但要排除具有特定userAgent的结果。 I've figured out the time range but cannot find anywhere that explains the exclude.
我已经确定了时间范围,但是找不到任何可以解释排除的地方。
Here's what I have for the query so far: 到目前为止,这是我的查询内容:
$dateRange = $collection->find(array("timeStamp" => array('$gt' => $start,
'$lt' => $end)));
Looking for code to complete the find function to exclude the records with a "userAgent" starting with "ELB" 寻找代码以完成查找功能,以排除以“ ELB”开头的“ userAgent”记录
What you're looking for is $ne or $nin, depending on whether the value you want to exclude is a single value or array of values. 您要查找的是$ ne或$ nin,这取决于要排除的值是单个值还是值数组。 eg:
例如:
$dateRange = $collection->find(array("timeStamp" => array('$gt' => $start, '$lt' => end), 'userAgent' => array('$ne' => new MongoRegex('/^ELB/'))));
Documentation here: 此处的文档:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24ne http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24nin http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24ne http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24nin
You could append {$not: /^ELB/}
to the mongo query. 您可以在mongo查询中附加
{$not: /^ELB/}
。
Not really sure about the equivalent PHP but try something like this: 不太确定是否等效的PHP,但可以尝试如下操作:
$dateRange = $collection->find(array(
'timeStamp' => array(
'$gt' => $start,
'$lt' => $end
),
'userAgent' => array(
'$not' => new MongoRegex('/^ELB/')
)
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.