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 SQL RDBMS DATABASE TABLE ROWS QUERY INDEX PARTITION MongoDB     DATABASE COLLECTION JSON DOCUMENT QUERY INDEX SHARD
INSERIR INSERT INTO USERS VALUES(1,1) $db->users->insert(array("a" => 1, "b" => 1)); //ou $query = array(      'usuario'    => "suissa",      'email' => "jnascimento@gmail.com" ); $db->collection->insert($query);
CONSULTAR select * from tabela where nome = 'Jean Nascimento'  $filter = array( &quot;nome&quot; => &quot;Jean Nascimento&quot; ); $cursor = $collection->find($filter); foreach ($cursor as $arr) {       echo $arr[&quot;nome&quot;]. &quot; - &quot; . $arr[&quot;_id&quot;] . &quot;<br />&quot;;  } 
CONSULTAR select * from tabela where nome LIKE 'J___ Nascimento' $filter = array( &quot;nome&quot; => new MongoRegex('/^J[a-Z]{3} Nascimento/i' ); select * from tabela where nome LIKE '%Nasc%'  $filter = array(   'title' => new MongoRegex('/.Nasc./i') );
ALTERAR update tarefas set Tarefa='Terminar artigo' where Usuario='suissa' $db->collection->update(      array('Usuario'=> 'suissa'),       array('$set' => array('Tarefa' => 'Terminar artigo')) );    update users set a=a+2 where b='q' $db->users->update(array(&quot;b&quot; => &quot;q&quot;), array('$inc => array(&quot;a&quot; => 2)));
EXCLUIR delete from usuarios where Usuario = 'suissa' $db->collection->remove(array('Usuario'=> 'suissa'));
EXPLAIN EXPLAIN SELECT * FROM users WHERE z=3 $db->users->find(array(&quot;z&quot; => 3))->explain()
 
 
 
 
Talk is cheap. Show me the  code .
  $nome_banco = ‘prioridades’; $nome_collection = ‘tarefas’; $this->conexao = new Mongo(); $this->db = $this->conexao->$nome_banco; $this->collection = $this->db->$nome_collection;
  function inserir(){      $this->query = array(     ‘ UsuarioID’ => $this->UsuarioID,     ‘ Usuario’ => $this->Usuario,     ‘ Tarefa’ => $this->Tarefa,     ‘ Tipo’ => $this->Tipo,//Obrigatório, idéia, outro     ‘ Prioridade’ => $this->Prioridade);      $this->collection->insert($this->query); }
  function excluir(){      $this->mongo_id = new MongoID($this->_id);      $this->collection->remove(array(‘_id’ => $this->mongo_id)); }    
  function mudar_tarefa(){      $this->mongo_id = new MongoID($this->_id);      $this->collection->update(array(‘_id’ => $this->mongo_id), array(‘$set’ => array(‘Tarefa’ => $this->Tarefa)), false); } 
  function mudar_tarefa(){      $this->mongo_id = new MongoID($this->_id);      $this->collection->update(array(‘_id’ => $this->mongo_id), array(‘$set’ => array(‘Tarefa’ => $this->Tarefa)), false); } 
  function mudar_prioridade(){      $this->mongo_id = new MongoID($this->_id);      if($this->modo==’up’){          $this->collection->update(              array(‘_id’ => $this->mongo_id),                               array(‘$inc’ => array(‘Prioridade’ => 1)),               false          );      } elseif($this->modo==’down’){          $this->collection->update(              array(‘_id’ => $this->mongo_id),               array(‘$inc’ => array(‘Prioridade’ => -1)),               false          );      } }
  https://github.com/suissa/mongodb-exemplos
Frameworks CakePHP Codeigniter Doctrine Drupal Fat-Free Kohana Lithium Memcached Symfony 2 TechMVC Vork Yii Zend
Standalone Tools ActiveMongo MapReduce API Mongofilesystem Mandango MongoDb PHP ODM Mongodloid MongoQueue MongoRecord Morph simplemongophp Uniform Server 6-Carbo with MongoDB and phpMoAdmin
Referências http://www.nosqlbr.com.br/ http://nosql-database.org/ http://pt.wikipedia.org/wiki/NoSQL http://www.mongodb.org/
 

Palestra sobre MongoDB com PHP no PHP'n'Rio

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