MongoCode::__construct
Creates a new code object
&reftitle.description;
public MongoCode::__construct
stringcode
arrayscopearray()
&reftitle.parameters;
code
A string of code.
scope
The scope to use for the code.
&reftitle.returnvalues;
Returns a new code object.
&reftitle.examples;
MongoCode::__construct example
4));
var_dump($code);
?>
]]>
&example.outputs.similar;
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; }"
}
]]>
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.
find(array('$where' => new MongoCode('function() { return this.x < y; }', array('y'=>$y))));
?>
]]>