downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

MongoCode::__toString> <MongoCode
[edit] Last updated: Fri, 18 Sep 2009

view this page in

MongoCode::__construct

(PECL mongo >= 0.8.3)

MongoCode::__constructCreates a new code object

Описание

MongoCode::__construct ( string $code [, array $scope = array() ] )

Параметри

code

A string of code.

scope

The scope to use for the code.

Връщани стойности

Returns a new code object.

Примери

Example #1 MongoCode::__construct() example

<?php

$code 
= new MongoCode('function(x) { for(i=0;i<10;i++) { db.foo.update({x:i}, {x:i+1}); } return x-1; }', array("x" => 4));
var_dump($code);

?>

Примерът по-горе ще изведе нещо подобно на:

object(MongoCode)#1 (2) {
  ["scope"]=>
  array(1) {
    ["x"]=>
    int(4)
  }
  ["code"]=>
  string(80) "function(x) { for(i=0;i<10;i++) { db.foo.update({x:i}, {x:i+1}); } return x-1; }"
}

Example #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))));

?>


add a note add a note User Contributed Notes MongoCode::__construct
There are no user contributed notes for this page.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites