我有一个字符串转换为 MongoDate 使用
$dateAdded = new MongoDate(strtotime("$time"));
echo "date ".$dateAdded;
所以我$dateAdded
现在的样子0.00000000 1482505458
。(这里 1482505458 是秒数,0.00000000 是微秒。)
现在,我的集合中有一个文档,其中 sec = 1482442458 和 usec = 622000。
Array ( [_id] => Array ( [addedtime] => MongoDate Object ( [sec] => 1482505458 [usec] => 622000 ) )
如何编写仅匹配秒字段的查询?
更新:
她的就是我一直在尝试的:
$date = "2016-12-23 15:04:18";
$m = new MongoClient("mongodb://172.29.0.186:27017");
$dateAdded = new MongoDate(strtotime("+330 minutes",strtotime("$time")));
echo " date ".$dateAdded;
$key = array('$and' => array(array('_id.createdby' => "$user"), array('_id.addedtime' => "$dateAdded")));
$collectionCount->find($key);
它应该匹配:
Array ( [_id.createdby] => 10006161 ) Array ( [_id] => Array ( [addedtime] => MongoDate Object ( [sec] => 1482505458 [usec] => 622000 ) [empname] => Praveen Valecha [createdby] => 10006161 ) )