(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))));
?>