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

Mongodb Maker Bundle Laravel Package

doctrine/mongodb-maker-bundle

View on GitHub
Deep Wiki
Context7
## Getting Started
This package, **Doctrine MongoDB Maker Bundle**, extends Laravel's built-in `maker-bundle` to support MongoDB document generation with Doctrine MongoDB ODM. To get started:

1. **Installation**:
   ```bash
   composer require doctrine/mongodb-maker-bundle

Ensure doctrine/mongodb-odm and symfony/maker-bundle are also installed.

  1. Publish Configuration (if needed):

    php artisan vendor:publish --provider="Doctrine\MongoDBMakerBundle\DoctrineMongoDBMakerBundle" --tag="config"
    
  2. First Use Case: Generate a new MongoDB document:

    php artisan make:document User
    

    This creates a User document class with basic fields, annotations, and repository setup.


Implementation Patterns

Core Workflows

  1. Document Generation:

    • Use make:document to scaffold a new document class with MongoDB-specific annotations (@Document, @Field, etc.).
    • Customize fields via --fields flag:
      php artisan make:document Post --fields="title:string,content:text,createdAt:date"
      
  2. Relationships:

    • Define relationships (e.g., ManyToOne, OneToMany) using the --relationships flag or manually in the generated class:
      // Example: One-to-Many relationship
      /** @ManyToOne(targetDocument="Comment") */
      private $author;
      
  3. Indexes:

    • Add indexes via make:index or directly in the document:
      /** @Index(keys={"title"="text", "createdAt"=-1}) */
      
  4. Search Indexes:

    • Generate search indexes for text-based queries:
      php artisan make:index User --search="title,description"
      

Integration Tips

  • Leverage Doctrine Annotations: Use @Document, @Field, @Index, and @ReferenceOne/@ReferenceMany for type safety and IDE autocompletion.
  • Extend Base Document: Override Doctrine\ODM\MongoDB\Mapping\Annotations\Document in your custom base class for shared behavior.
  • Validation: Use Symfony’s validation constraints (e.g., @Assert\NotBlank) alongside MongoDB-specific rules.
  • Testing: Mock the DocumentManager in unit tests to avoid real database dependencies.

Gotchas and Tips

Pitfalls

  1. Field Type Mismatches:

    • MongoDB ODM uses specific types (e.g., DateTime, ArrayCollection). Avoid PHP native types like array or string without casting.
    • Example: Use DateTime instead of string for dates.
  2. Relationship Direction:

    • Bidirectional relationships require manual inverse-side configuration (e.g., mappedBy/inversedBy in @OneToMany).
  3. Index Conflicts:

    • Duplicate index names or keys will cause runtime errors. Validate indexes via:
      php artisan doctrine:schema:validate
      
  4. Collection Attribute:

    • The package removes the Collection attribute (PR #6). Use ArrayCollection or array with @Field(type="array") instead.

Debugging

  • Schema Validation:

    php artisan doctrine:schema:validate
    

    Fixes errors before running migrations.

  • Log Queries: Enable Doctrine logging in config/packages/doctrine_mongodb_odm.yaml:

    logging:
        enabled: true
        level: DEBUG
    

Extension Points

  1. Custom Templates: Override the default maker templates by publishing and modifying:

    php artisan vendor:publish --tag="mongodb-maker-templates"
    
  2. Commands: Extend existing commands (e.g., make:document) by creating a custom command that calls the bundle’s base command and adds logic.

  3. Field Types: Add custom field types by implementing Doctrine\ODM\MongoDB\Mapping\Driver\Driver and registering it in the bundle’s configuration.

  4. Validation Rules: Extend the validator by overriding the Doctrine\MongoDBMakerBundle\Validator class and updating the service configuration.


NO_UPDATE_NEEDED would **not** apply here due to the introduction of new features and workflows.
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.
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php