Installation:
composer require akeneo-labs/direct-to-mongodb
(Note: Only relevant for Akeneo PIM 1.4.0–1.4.12 with MongoDB storage. Deprecated in 1.4.13+.)
Enable the Bundle:
Add to app/AppKernel.php (or config/bundles.php for Symfony 4+):
new Akeneo\Bundle\DirectToMongoDBBundle\AkeneoDirectToMongoDBBundle(),
First Use Case:
config.yml:
akeneo_direct_to_mongodb:
enabled: true
Bulk Product Imports:
enabled: true in config. The bundle hooks into ProductSaver to use raw MongoDB writes.Event-Driven Extensions:
ProductSaver, ensure custom logic doesn’t rely on ODM events (e.g., prePersist, preUpdate). Use MongoDB’s native $pre/$post hooks instead.// Override ProductSaver to leverage direct writes
$saver = $this->get('akeneo_direct_to_mongodb.product_saver');
$saver->save($product);
Performance Tuning:
sku, family_variant).Hybrid Workflows:
Deprecation Warning:
Event System Conflicts:
ProductSaver extensions may fail if they assume ODM events (e.g., onFlush()).Data Consistency:
$unique indexes.Doctrine ODM Compatibility:
doctrine/mongodb-odm-bundle ≥3.1.0 (this bundle targets beta versions).v3.0.0-BETA6 in composer.json if using this bundle.Enable Logging:
Add to config.yml to trace direct writes:
akeneo_direct_to_mongodb:
enabled: true
debug: true # Logs MongoDB operations to `monolog`
MongoDB Profiling:
Use db.setProfilingLevel(1) in MongoDB shell to analyze slow bulk operations.
Fallback Mechanism:
try {
$this->directSaver->save($product);
} catch (\Exception $e) {
$this->odmSaver->save($product); // Fallback
}
Custom Writers:
Extend Akeneo\Bundle\DirectToMongoDBBundle\Writer\ProductWriter to add pre-processing (e.g., data transformation):
class CustomProductWriter extends ProductWriter {
protected function transformProduct(Product $product) {
// Modify $product->getData() before save
}
}
Register as a service:
services:
akeneo_direct_to_mongodb.writer.product:
class: AppBundle\Writer\CustomProductWriter
tags:
- { name: akeneo_direct_to_mongodb.writer }
Bulk Optimizations:
Override saveAll() to use MongoDB’s insertMany() for arrays of products:
public function saveAll(array $products) {
$collection = $this->getCollection();
$collection->insertMany($this->transformBatch($products));
}
How can I help you explore Laravel packages today?