Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
com Jean Carlo Nascimento aka SUISSA
github.com/suissa about.me/suissa nosqlbr.com.br @osuissa
NOSQL O que é? Quais são? Por que usar? Onde usar?
 
 
 
 
 
 
 
 
key/value
 
graph
 
 
 
 
 
 
 
 
 
Terminologia <ul><li>SQL RDBMS </li></ul><ul><li>DATABASE </li></ul><ul><li>TABLE </li></ul><ul><li>ROWS </li></ul><ul><li...
INSERIR <ul><li>INSERT INTO USERS VALUES(1,1) </li></ul><ul><li>$db->users->insert(array(&quot;a&quot; => 1, &quot;b&quot;...
CONSULTAR <ul><li>select * from tabela where nome = 'Jean Nascimento'  </li></ul><ul><li>$filter = array( &quot;nome&quot;...
CONSULTAR <ul><li>select * from tabela where nome LIKE 'J___ Nascimento' </li></ul><ul><li>$filter = array( &quot;nome&quo...
ALTERAR <ul><li>update tarefas set Tarefa='Terminar artigo' where Usuario='suissa' </li></ul><ul><li>$db->collection->upda...
EXCLUIR <ul><li>delete from usuarios where Usuario = 'suissa' </li></ul><ul><li>$db->collection->remove(array('Usuario'=> ...
EXPLAIN <ul><li>EXPLAIN SELECT * FROM users WHERE z=3 </li></ul><ul><li>$db->users->find(array(&quot;z&quot; => 3))->expla...
 
 
 
<ul><li>  </li></ul>
Talk is cheap. Show me the  code .
  <ul><li>$nome_banco = ‘prioridades’; $nome_collection = ‘tarefas’; </li></ul><ul><li>$this->conexao = new Mongo(); $this...
  <ul><li>function inserir(){ </li></ul><ul><li>     $this->query = array( </li></ul><ul><li>    ‘ UsuarioID’ => $this->Us...
  <ul><li>function excluir(){ </li></ul><ul><li>     $this->mongo_id = new MongoID($this->_id); </li></ul><ul><li>     $th...
  <ul><li>function mudar_tarefa(){ </li></ul><ul><li>     $this->mongo_id = new MongoID($this->_id); </li></ul><ul><li>   ...
  <ul><li>function mudar_tarefa(){ </li></ul><ul><li>     $this->mongo_id = new MongoID($this->_id); </li></ul><ul><li>   ...
  <ul><li>function mudar_prioridade(){ </li></ul><ul><li>     $this->mongo_id = new MongoID($this->_id); </li></ul><ul><li...
  <ul><li>https://github.com/suissa/mongodb-exemplos </li></ul>
Frameworks <ul><li>CakePHP Codeigniter Doctrine Drupal Fat-Free Kohana </li></ul>Lithium Memcached Symfony 2 TechMVC Vork ...
Standalone Tools <ul><li>ActiveMongo </li></ul><ul><li>MapReduce API </li></ul><ul><li>Mongofilesystem </li></ul><ul><li>M...
Referências <ul><li>http://www.nosqlbr.com.br/ </li></ul><ul><li>http://nosql-database.org/ </li></ul><ul><li>http://pt.wi...
 
Upcoming SlideShare
Loading in …5
×

Palestra sobre MongoDB com PHP no PHP'n'Rio

5,318 views

Published on

Palestra sobre MongoDB com PHP no PHP'n'Rio

Published in: Technology

Palestra sobre MongoDB com PHP no PHP'n'Rio

  1. 1. com Jean Carlo Nascimento aka SUISSA
  2. 2. github.com/suissa about.me/suissa nosqlbr.com.br @osuissa
  3. 3. NOSQL O que é? Quais são? Por que usar? Onde usar?
  4. 12. key/value
  5. 14. graph
  6. 24. Terminologia <ul><li>SQL RDBMS </li></ul><ul><li>DATABASE </li></ul><ul><li>TABLE </li></ul><ul><li>ROWS </li></ul><ul><li>QUERY </li></ul><ul><li>INDEX </li></ul><ul><li>PARTITION </li></ul>MongoDB     DATABASE COLLECTION JSON DOCUMENT QUERY INDEX SHARD
  7. 25. INSERIR <ul><li>INSERT INTO USERS VALUES(1,1) </li></ul><ul><li>$db->users->insert(array(&quot;a&quot; => 1, &quot;b&quot; => 1)); </li></ul><ul><li>//ou </li></ul><ul><li>$query = array( </li></ul><ul><li>    'usuario'    => &quot;suissa&quot;, </li></ul><ul><li>    'email' => &quot;jnascimento@gmail.com&quot; </li></ul><ul><li>); </li></ul><ul><li>$db->collection->insert($query); </li></ul>
  8. 26. CONSULTAR <ul><li>select * from tabela where nome = 'Jean Nascimento'  </li></ul><ul><li>$filter = array( &quot;nome&quot; => &quot;Jean Nascimento&quot; ); </li></ul><ul><li>$cursor = $collection->find($filter); </li></ul><ul><li>foreach ($cursor as $arr) {  </li></ul><ul><li>     echo $arr[&quot;nome&quot;]. &quot; - &quot; . $arr[&quot;_id&quot;] . &quot;<br />&quot;;  </li></ul><ul><li>}  </li></ul>
  9. 27. CONSULTAR <ul><li>select * from tabela where nome LIKE 'J___ Nascimento' </li></ul><ul><li>$filter = array( &quot;nome&quot; => new MongoRegex('/^J[a-Z]{3} </li></ul><ul><li>Nascimento/i' ); </li></ul><ul><li>select * from tabela where nome LIKE '%Nasc%'  </li></ul><ul><li>$filter = array(   'title' => new MongoRegex('/.Nasc./i') ); </li></ul>
  10. 28. ALTERAR <ul><li>update tarefas set Tarefa='Terminar artigo' where Usuario='suissa' </li></ul><ul><li>$db->collection->update( </li></ul><ul><li>     array('Usuario'=> 'suissa'),  </li></ul><ul><li>     array('$set' => array('Tarefa' => 'Terminar artigo')) </li></ul><ul><li>);    </li></ul><ul><li>update users set a=a+2 where b='q' </li></ul><ul><li>$db->users->update(array(&quot;b&quot; => &quot;q&quot;), array('$inc => array(&quot;a&quot; => 2))); </li></ul>
  11. 29. EXCLUIR <ul><li>delete from usuarios where Usuario = 'suissa' </li></ul><ul><li>$db->collection->remove(array('Usuario'=> 'suissa')); </li></ul>
  12. 30. EXPLAIN <ul><li>EXPLAIN SELECT * FROM users WHERE z=3 </li></ul><ul><li>$db->users->find(array(&quot;z&quot; => 3))->explain() </li></ul>
  13. 34. <ul><li>  </li></ul>
  14. 35. Talk is cheap. Show me the  code .
  15. 36.   <ul><li>$nome_banco = ‘prioridades’; $nome_collection = ‘tarefas’; </li></ul><ul><li>$this->conexao = new Mongo(); $this->db = $this->conexao->$nome_banco; $this->collection = $this->db->$nome_collection; </li></ul>
  16. 37.   <ul><li>function inserir(){ </li></ul><ul><li>     $this->query = array( </li></ul><ul><li>    ‘ UsuarioID’ => $this->UsuarioID, </li></ul><ul><li>    ‘ Usuario’ => $this->Usuario, </li></ul><ul><li>    ‘ Tarefa’ => $this->Tarefa, </li></ul><ul><li>    ‘ Tipo’ => $this->Tipo,//Obrigatório, idéia, outro </li></ul><ul><li>    ‘ Prioridade’ => $this->Prioridade); </li></ul><ul><li>     $this->collection->insert($this->query); </li></ul><ul><li>} </li></ul>
  17. 38.   <ul><li>function excluir(){ </li></ul><ul><li>     $this->mongo_id = new MongoID($this->_id); </li></ul><ul><li>     $this->collection->remove(array(‘_id’ => $this->mongo_id)); </li></ul><ul><li>}     </li></ul>
  18. 39.   <ul><li>function mudar_tarefa(){ </li></ul><ul><li>     $this->mongo_id = new MongoID($this->_id); </li></ul><ul><li>     $this->collection->update(array(‘_id’ => $this->mongo_id), array(‘$set’ => array(‘Tarefa’ => $this->Tarefa)), false); </li></ul><ul><li>}  </li></ul>
  19. 40.   <ul><li>function mudar_tarefa(){ </li></ul><ul><li>     $this->mongo_id = new MongoID($this->_id); </li></ul><ul><li>     $this->collection->update(array(‘_id’ => $this->mongo_id), array(‘$set’ => array(‘Tarefa’ => $this->Tarefa)), false); </li></ul><ul><li>}  </li></ul>
  20. 41.   <ul><li>function mudar_prioridade(){ </li></ul><ul><li>     $this->mongo_id = new MongoID($this->_id); </li></ul><ul><li>     if($this->modo==’up’){ </li></ul><ul><li>         $this->collection->update( </li></ul><ul><li>             array(‘_id’ => $this->mongo_id),                  </li></ul><ul><li>             array(‘$inc’ => array(‘Prioridade’ => 1)),  </li></ul><ul><li>             false </li></ul><ul><li>         ); </li></ul><ul><li>     } elseif($this->modo==’down’){ </li></ul><ul><li>         $this->collection->update( </li></ul><ul><li>             array(‘_id’ => $this->mongo_id),  </li></ul><ul><li>             array(‘$inc’ => array(‘Prioridade’ => -1)),  </li></ul><ul><li>             false </li></ul><ul><li>         ); </li></ul><ul><li>     } </li></ul><ul><li>} </li></ul>
  21. 42.   <ul><li>https://github.com/suissa/mongodb-exemplos </li></ul>
  22. 43. Frameworks <ul><li>CakePHP Codeigniter Doctrine Drupal Fat-Free Kohana </li></ul>Lithium Memcached Symfony 2 TechMVC Vork Yii Zend
  23. 44. Standalone Tools <ul><li>ActiveMongo </li></ul><ul><li>MapReduce API </li></ul><ul><li>Mongofilesystem </li></ul><ul><li>Mandango </li></ul><ul><li>MongoDb PHP ODM </li></ul><ul><li>Mongodloid </li></ul>MongoQueue MongoRecord Morph simplemongophp Uniform Server 6-Carbo with MongoDB and phpMoAdmin
  24. 45. Referências <ul><li>http://www.nosqlbr.com.br/ </li></ul><ul><li>http://nosql-database.org/ </li></ul><ul><li>http://pt.wikipedia.org/wiki/NoSQL </li></ul><ul><li>http://www.mongodb.org/ </li></ul>

×