[英]Why doesn't this PHP MongoDB query return any results even though there is one?
I have a collection of users and users have a meta.create_date field which is an ISODate as seen below. 我有一个用户集合,用户有一个meta.create_date字段,它是一个ISODate,如下所示。 I am trying to count how many users were created in the last N days. 我试图计算在过去N天内创建了多少用户。 I have the following in the database: 我在数据库中有以下内容:
{
"_id" : ObjectId("51e61fa16803fa40130a0581"),
"meta" : {
"create_date" : ISODate("2013-07-17T04:37:53.355Z")
}
}
My PHP code: 我的PHP代码:
$daysAgo = new MongoDate(date('c', strtotime('-7 days')));
$query = array(
'meta.create_date' => array(
'$gte' => $daysAgo,
)
);
$result = $this->db->users->count($query);
I have also tried specifying a range using '$gte' and '$lte' where $lte => today. 我还尝试使用'$ gte'和'$ lte'指定范围,其中$ lte =>今天。
However, result is coming back as 0. So what is going on here? 然而,结果又回到了0.那么这里发生了什么?
MongoDate() takes int time(). MongoDate()接受int time()。 So, passing in a php date() to the constructor does not work. 因此,将php date()传递给构造函数不起作用。 This is the proper way: 这是正确的方法:
$daysAgo = new MongoDate(strtotime('-7 days'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.