我需要将此查询从 php 转换为 mongoDB 查询
$query = "select * from table where data_added like '%data%';
我将日期存储在变量中
$date = "2013-09-02";
在我的 mongo 文档中,日期排序为:
$dateAdded = new MongoDate(strtotime('2013-09-02 12:21:55'));
I tried
$date = new MongoDate(strtotime("$date"));
$mongo->find(array('date_added'=>array('$lt'=>$date)));
and
$mongo->find(array('date_added'=>$date));
但没有成功。
所以我需要使用查询(Y-m-d) not (年-月-日 小时:i:s)那么如何在mongo中使用LIKE查询数据
Thanks
您需要进行范围查询。创建一个时间戳,例如使用 strtotime(),以获取一天开始时的 Unix 时间戳,以及另一天结束时的时间戳。
根据您想要这两端包含还是排除,然后使用
// Both points/seconds inclusive
->find(array("date" => array('$gte' => $startOfDay, '$lte' => $endOfDay)));
// Both seconds exclusive
->find(array("date" => array('$gt' => $startOfDay, '$lt' => $endOfDay)));
See http://cookbook.mongodb.org/patterns/date_range/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)