从MongoDB中存储的Javascript查询

时间:2013-07-26 20:32:40

标签: php mongodb

我正在尝试在mongodb的存储javascript中存储查询,如下所示:

$query = $collection->count(array( 'email' => "me@hotmail.com", 'app_id' => $app_id ));

$db->system->js->save(array(
    "_id" => "archiveMessages2", 
    "value" => new MongoCode("function() { $query }")
));

然后我尝试通过执行这样的函数来运行查询: print_r($db->execute("archiveMessages2()"));

但它不会返回任何东西。

请帮忙

1 个答案:

答案 0 :(得分:0)

现在就知道了,只需要像

一样添加'return'

"value" => new MongoCode("function() { return $query }")