(PECL mongo >= 0.8.3)
MongoCode::__construct — ����һ���µĴ������
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
�ַ������롣
scope
ʹ�ô���ķ�Χ��
����һ���µĴ������
Example #1 MongoCode::__construct() ����
<?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; }" }
Example #2 ʹ�þ��� $where �� MongoCode
������Ӳ�ѯ�˼����'x' �ֶα� $y С��Ԫ�ء� ע�⣬PHP �����ܹ����뵽 JavaScript ������Ȼ�� JavaScript ��������һ�� boolean��
<?php
$cursor = $collection->find(array('$where' => new MongoCode('function() { return this.x < y; }', array('y'=>$y))));
?>