Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Direct To Mongodb Laravel Package

akeneo-labs/direct-to-mongodb

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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+.)

  2. Enable the Bundle: Add to app/AppKernel.php (or config/bundles.php for Symfony 4+):

    new Akeneo\Bundle\DirectToMongoDBBundle\AkeneoDirectToMongoDBBundle(),
    
  3. First Use Case:

    • Problem: Slow product imports via Akeneo’s default ODM writer.
    • Solution: This bundle bypasses Doctrine’s ODM event system for direct MongoDB writes, improving bulk-save performance.
    • Trigger: Enable via Akeneo’s config.yml:
      akeneo_direct_to_mongodb:
          enabled: true
      

Implementation Patterns

Workflow Integration

  1. Bulk Product Imports:

    • Use with Akeneo’s CSV import tool for MongoDB storage.
    • Pattern: Disable default ODM events by setting enabled: true in config. The bundle hooks into ProductSaver to use raw MongoDB writes.
  2. Event-Driven Extensions:

    • Pre/Post-Save Logic: If extending Akeneo’s ProductSaver, ensure custom logic doesn’t rely on ODM events (e.g., prePersist, preUpdate). Use MongoDB’s native $pre/$post hooks instead.
    • Example:
      // Override ProductSaver to leverage direct writes
      $saver = $this->get('akeneo_direct_to_mongodb.product_saver');
      $saver->save($product);
      
  3. Performance Tuning:

    • Batch Sizes: Test with chunks of 100–500 products to balance memory and write speed.
    • Indexing: Ensure MongoDB indexes are optimized for your product attributes (e.g., sku, family_variant).
  4. Hybrid Workflows:

    • Partial Adoption: Use the bundle only for high-volume imports, keeping default ODM for critical updates (e.g., inventory changes).

Gotchas and Tips

Pitfalls

  1. Deprecation Warning:

    • This bundle is obsolete for Akeneo ≥1.4.13 (direct writes became default). Avoid in new projects.
  2. Event System Conflicts:

    • Symptom: Custom ProductSaver extensions may fail if they assume ODM events (e.g., onFlush()).
    • Fix: Use MongoDB’s native hooks or refactor to post-save logic.
  3. Data Consistency:

    • Risk: Direct writes skip Akeneo’s validation layer (e.g., unique SKU checks).
    • Mitigation: Validate data before bulk inserts or use MongoDB’s $unique indexes.
  4. Doctrine ODM Compatibility:

    • Issue: Conflicts with doctrine/mongodb-odm-bundle ≥3.1.0 (this bundle targets beta versions).
    • Workaround: Pin to v3.0.0-BETA6 in composer.json if using this bundle.

Debugging Tips

  1. Enable Logging: Add to config.yml to trace direct writes:

    akeneo_direct_to_mongodb:
        enabled: true
        debug: true  # Logs MongoDB operations to `monolog`
    
  2. MongoDB Profiling: Use db.setProfilingLevel(1) in MongoDB shell to analyze slow bulk operations.

  3. Fallback Mechanism:

    • If direct writes fail, implement a retry logic with the default ODM saver:
      try {
          $this->directSaver->save($product);
      } catch (\Exception $e) {
          $this->odmSaver->save($product); // Fallback
      }
      

Extension Points

  1. 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 }
    
  2. 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));
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver