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
MongoDB
DATABASE
TABLE
ROWS
QUERY
INDEX
PARTITION
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' => "[email protected]"
);
$db->collection->insert($query);
CONSULTAR
select * from tabela where nome = 'Jean Nascimento'
$filter = array( "nome" => "Jean Nascimento" );
$cursor = $collection->find($filter);
foreach ($cursor as $arr) {
echo $arr["nome"]. " - " . $arr["_id"] . "<br />";
}
CONSULTAR
select * from tabela where nome LIKE 'J___ Nascimento'
$filter = array( "nome" => 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("b" => "q"), array('$inc => array("a"
=> 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("z" => 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
MongoQueue
MapReduce API
MongoRecord
Mongofilesystem
Morph
Mandango
simplemongophp
MongoDb PHP ODM
Uniform Server 6-Carbo with
MongoDB and phpMoAdmin
Mongodloid
Referências
http://www.nosqlbr.com.br/
http://nosql-database.org/
http://pt.wikipedia.org/wiki/NoSQL
http://www.mongodb.org/
Download

phpnriomongodbcomphp-111107054202