Professional Documents
Culture Documents
Mongo Phpbnl12
Mongo Phpbnl12
Mongo Phpbnl12
2uthor o- 3de0ug
5ndex
@m ; ne" 8ongo.Amongod0#%%localhostA1B
@m ; ne" 8ongo.Alocalhost#2(01(A1B
@m ; ne" 8ongo.Amongod0#%%localhost#2C000A1B
@m ; ne"
8ongo.Amongod0#%%mongo!exam$le!comA1B
@m ; ne"
8ongo.Amongod0#%%md01!exam$le!com,md02!exa
m$le!comA1B
Documents
null
0oolean
dou0le
string .E7F-81
arra/
associati+e arra/
8ongoRegex
8ongo5d
8ongoDate
8ongo:ode
8ongoBinData
!Ds
@mod .modulo1
,ogical#
@not
Ad+anced ,uerying o"erators
2rra/#
8ongo:ursor-Iex$lain.1!
<?php ini_se('xdebug.var_disp1ay_max_deph', 1),
$m = new Mongo,
$c = $m->demo->e1ephpans,
$c->drop(),
$c->inser( array( '_id' => 'e1e1', 'name' => 'Jumbo' ) ),
$c->inser( array( '_id' => 'e1e2', 'name' => 'Tanor' ) ),
var_dump( $c->find( [ '_id' => 'e1e1' | )->exp1ain() ),
?>
!ndexes
<?php ini_se('xdebug.var_disp1ay_max_deph', 1),
$m = new Mongo,
$c = $m->demo->e1ephpans,
$c->drop(),
$c->inser( [ '_id' => 'e1e1', 'name' => 'Jumbo' | ),
$c->inser( [ '_id' => 'e1e2', 'name' => 'Tanor' | ),
$c->inser( [ '_id' => 'e1e3', 'name' => 'Sampy' | ),
var_dump( $c->find( [ 'name' => 'Jumbo' | )->exp1ain() ),
?>
!ndexes
<?php ini_se('xdebug.var_disp1ay_max_deph', 1),
$m = new Mongo,
$c = $m->demo->e1ephpans,
$c->drop(),
$c->ensureIndex( [ 'name' => 1 | ),
$c->inser( [ '_id' => 'e1e1', 'name' => 'Jumbo' | ),
$c->inser( [ '_id' => 'e1e2', 'name' => 'Tanor' | ),
$c->inser( [ '_id' => 'e1e3', 'name' => 'Sampy' | ),
var_dump( $c->find( [ 'name' => 'Jumbo' | )->exp1ain() ),
?>
Geos"atial !ndexes
Hel$s /ou "ith -inding locations .$u0sJ1 in a 2D
s$ace
<?php
$m = new Mongo, $c = $m->demo->pubs, $c->drop(),
$c->ensureIndex( array( '1ocaion' => '2d' ) ),
$c->inser( [ '_id' => 'pub1', 'name' => 'Mrs Besy Smih', '1ocaion' => [ -0.1933, 51.5375 | | ),
$c->inser( [ '_id' => 'pub2', 'name' => 'Norh London Tavern', '1ocaion' => [ -0.2025, 51.5455 | | ),
$c1oses = $m->demo->command( [
'geoNear' => 'pubs',
'near' => [ -0.198, 51.538 |,
'spherica1' => rue,
| ),
//var_dump( $c1oses['sas'| ),
foreach ( $c1oses['resu1s'| as $res ) {
prinf( "%s: %.2f 'm\n", $res['ob_'|['name'|, $res['dis'| * 6378 ),,
}
?>
ommands
@sort
@limit % @ski$
Aggregation 3xam"le
<?php
$m = new Mongo, $d = $m->demo, $c = $d->aric1es, $c->drop(),
$c->inser( [
"i1e" => "Rrofi1ing RHR App1icaions",
"ur1" => "hp://deric'rehans.n1/a1's/profi1ing-phpour1i11e11.pdf",
"ags" => [ "php", "profi1ing" |
| ),
$c->inser( [
"i1e" => "Xdebug",
"ur1" => "hp://deric'rehans.n1/a1's/xdebug-phpbcn11.pdf",
"ags" => [ "php", "xdebug" |
| ),
$m = $d->command( [
'aggregae' => 'aric1es',
'pipe1ine' => [
[ '$mach' => [ 'ags' => 'php' | |,
[ '$unwind' => '$ags' |,
[ '$pro_ec' => [
'i1e' => [ '$add' => [ '$i1e', ': ', '$ur1' | |,
'ag' => '$ags'
| |
|
| ),
foreach( $m['resu1'| as $res ) { echo $res['i1e'|, ' (', $res['ag'|, ")\n", }
?>
Tools and monitoring
Do"nload mongoDB#
htt$#%%"""!mongod0!org%do"nloads
Feed0ack# htt$#%%&oind!in%'()*