我正在尝试使用存储的 javascript 在 MongoDB 中存储查询。
现在看起来像这样:
$collection = $db->$app_id;
$query = $collection->find( $filterQuery );
$db->system->js->save(array(
"_id" => "qo8qu0",
"value" => new MongoCode("function() { return array($query) }")
));
然后我执行它:
echo "<pre>";
print_r($test = $db->execute("qo8qu0()"));
echo "</pre>";
但是,我收到此错误:
Catchable fatal error: Object of class MongoCursor could not be converted to string in /var/www/dev/classes/EmailMessaging.php on line 91
第 91 行就是这一行(如上),
"value" => new MongoCode("function() { return array($filterQuery) }")
如果我使用count( $filterQuery );
而不是find( $filterQuery );
它可以工作并返回正确的数字。
我怎样才能使它工作,以便在使用时返回数组find
?
谢谢