我正在处理长整型。
我在php中形成了一个查询数组,如下所示:
$find_count = array("key"=>$keyword, "type"=>$type, "fromTime"=>array('$gt'=> $fromTimeEpoch, "'$lte" => $toTimeEpoch));
$cursor_count = $coll_count->find($find_count, $projection_count);//Query mongodb. $coll_count is a MongoDB collection.
这里$fromTimeEpoch和$toTimeEpoch是LONG变量。
当我回显$find_count时,$fromSimeEpoch和$toTimeEpoch被打印得很好(大约1372617000000)
然而,这些查询没有正确到达mongo服务器。mongo服务器接收到的$fromTimeEpoch和$toTimeEpoch的值是负整数(类似于1858934720)。
所以问题是,为什么这些LONG会转化为负值?
在php中传递长变量的正确方法是什么?
注意:在我的mongo数据库中,"fromTime"字段的类型是LONG(而不是STRING)。
如果你处理时间并按时间搜索,你应该使用MongoDate()
$start = new MongoDate(strtotime("2010-01-15 00:00:00"));
$end = new MongoDate(strtotime("2010-01-30 00:00:00"));
// find dates between 1/15/2010 and 1/30/2010
$collection->find(array("ts" => array('$gt' => $start, '$lte' => $end)));