简体   繁体   中英

Find from mongodb in php

I try to fine this time and this name by this code

$start = new MongoDate(strtotime("00:00:00"));
$end = new MongoDate(strtotime("8:00:00"));
$t= $collection->find('$and' => array( array('date' => array('$gt' => $start, '$lte' => $end)),array('name' =>$name)));

but i get

Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in {C:\xampp\htdocs\test\result.php on line 305}

so why i get this?

The find function accepts an array, but you gave something that's not of any variable type ( '$and' => array() ). I'm not sure how to correct your code because it's unclear to me what you are looking for, but from a syntax point of view, removing the '$and' => should work.

$t= $collection->find(['$and' => array('date' => array('$gt' => $start, '$lte' => $end),array('name' =>$name))]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM