MongoCode::__construct
(PECL mongo >= 0.8.3)
MongoCode::__construct — Creates a new code object
This extension that defines this method is deprecated. Instead, the MongoDB extension should be used. Alternatives to this method include:
Описание
$code
[, array $scope
= array()
] )Список параметров
-
code
-
A string of code.
-
scope
-
The scope to use for the code.
Возвращаемые значения
Returns a new code object.
Примеры
Пример #1 MongoCode::__construct() example
<?php
$code = new MongoCode('function() { '.
'for(i=0;i<10;i++) {'.
'db.foo.update({z : i}, {z : x});'.
'}'.
'return x-1;'.
'}', array("x" => 4));
var_dump($code);
?>
Результатом выполнения данного примера будет что-то подобное:
object(MongoCode)#1 (2) { ["scope"]=> array(1) { ["x"]=> int(4) } ["code"]=> string(80) "function() { for(i=0;i<10;i++) { db.foo.update({z : i}, {z : x}); } return x-1; }" }
Пример #2 Using MongoCode with $where
This example queries a collection for elements where the 'x' fields is less than $y. Notice that PHP objects can be passed into the JavaScript scope and that the JavaScript function returns a boolean.
<?php
$cursor = $collection->find(array('$where' => new MongoCode('function() { return this.x < y; }', array('y'=>$y))));
?>
Коментарии
404 Not Found