Add Repository & Dependencies
Update composer.json with the VCS repository and required packages:
"repositories": [
{ "type": "vcs", "url": "https://github.com/m0ppers/MopArangoDbBundle.git" }
],
"require": {
"mop/arangodbbundle": "dev-master",
"triagens/ArangoDb": "2.0.*"
}
Run composer update.
Enable the Bundle
Add to app/AppKernel.php:
new Mop\ArangoDbBundle\MopArangoDbBundle(),
Configure a Connection
Define a connection in app/config/config.yml:
mop_arango_db:
connections:
main:
host: 'localhost'
port: 8529
username: 'root'
password: ''
database: 'your_db'
First Query
Inject the ArangoDb\Client service (via triagens/ArangoDb) into a controller/service:
use ArangoDb\Client;
class MyController extends Controller
{
public function index(Client $arangodb)
{
$collection = $arangodb->db('your_db')->collection('users');
$users = $collection->all();
return $this->render('users/index.html.twig', ['users' => $users]);
}
}
default_connection in config to avoid repetitive injection.services:
my.service:
arguments: ['@mop_arango_db.connection.main']
config_dev.yml/config_prod.yml.Basic CRUD:
// Create
$collection->insert(['name' => 'John', 'email' => 'john@example.com']);
// Read
$users = $collection->byExample(['name' => 'John'])->toArray();
// Update
$user = $collection->get('user_id');
$user->name = 'John Doe';
$user->save();
// Delete
$collection->remove($user);
AQL Queries:
$query = $arangodb->query('FOR u IN users FILTER u.age > 25 RETURN u');
$result = $query->execute();
Transactions:
$transaction = $arangodb->beginTransaction();
try {
$transaction->collection('users')->insert([...]);
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollback();
}
FOS\UserBundle\Model\User and map to ArangoDB collections:
class ArangoUser extends BaseUser
{
public function getId()
{
return $this->getKey(); // ArangoDB key
}
}
FOS\UserBundle\Model\UserInterface and use triagens/ArangoDb methods.config_dev.yml:
mop_arango_db:
data_collector: true
triagens/ArangoDb methods or a third-party mapper (e.g., ArangoPHP).getId() method must return a string (ArangoDB key), not an integer.loadUserByUsername() in your user provider to query ArangoDB directly.Client instance for efficiency.triagens/ArangoDb v2.x has breaking changes. Check migration guide.mop_arango_db:
logging: true
Logs appear in app/logs/dev.log.arangosh) to isolate issues.arangosh --javascript.execute 'db._createDatabase("your_db")'
config.yml:
mop_arango_db:
connections:
secure:
host: 'arangodb.example.com'
port: 8529
ssl: true
class UserCollection
{
public function __construct(Client $arangodb)
{
$this->collection = $arangodb->db('your_db')->collection('users');
}
public function findByEmail($email)
{
return $this->collection->byExample(['email' => $email])->first();
}
}
Mop\ArangoDbBundle\DataCollector\ArangoDbDataCollector for additional metrics.batch() for bulk inserts/updates:
$batch = $collection->batch();
foreach ($users as $user) {
$batch->insert($user);
}
$batch->execute();
$collection->ensureIndex(['name' => true]);
How can I help you explore Laravel packages today?