cakeweb / mongodb
ODM para MongoDB com PHP7
Installs: 443
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:git
Requires
- cakeweb/exception: ^1.0.0
- cakeweb/helper: ^1.0.0
- cakeweb/httpstatuscode: ^1.0.0
- cakeweb/registry: ^1.0.0
- mongodb/mongodb: ^1.0.0
This package is auto-updated.
Last update: 2024-12-24 10:28:38 UTC
README
Instalação: composer require cakeweb/mongodb
Exemplo de uso:
use CakeWeb\MongoDB\Connection; use CakeWeb\MongoDB\Collection; use CakeWeb\MongoDB\Document; class Usuarios extends Collection { const COLLECTION_NAME = 'usuarios'; const DOCUMENT_CLASS = 'Usuario'; } class Usuario extends Document { const COLLECTION_CLASS = 'Usuarios'; public function setNome($nome) { $this->data['nome'] = $nome; return $this; } } try { Connection::init('127.0.0.1:27017', 'data-db', 'user', 'pass', 'auth-db'); // Collection $usuarios = Usuarios::getInstance(); // Cadastra um Document na Collection $usuario = $usuarios->newDocument(); // ou $usuario = new Usuario(); $usuario->setNome('Novo usuário'); $usuario->save(); // para obter o id recém-gerado: $usuario->getId(); // Atualiza um Document da Collection $usuario = $usuarios->findOne(['_id' => new MongoDB\BSON\ObjectID('57ca3b4bc4105c277800435b')]); if($usuario) { $usuario->setNome('Novo nome'); $usuario->save(); } } catch(Exception $e) { echo $e->getMessage(); }