doctrine/mongodb-maker-bundle
## 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.
Publish Configuration (if needed):
php artisan vendor:publish --provider="Doctrine\MongoDBMakerBundle\DoctrineMongoDBMakerBundle" --tag="config"
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.
Document Generation:
make:document to scaffold a new document class with MongoDB-specific annotations (@Document, @Field, etc.).--fields flag:
php artisan make:document Post --fields="title:string,content:text,createdAt:date"
Relationships:
ManyToOne, OneToMany) using the --relationships flag or manually in the generated class:
// Example: One-to-Many relationship
/** @ManyToOne(targetDocument="Comment") */
private $author;
Indexes:
make:index or directly in the document:
/** @Index(keys={"title"="text", "createdAt"=-1}) */
Search Indexes:
php artisan make:index User --search="title,description"
@Document, @Field, @Index, and @ReferenceOne/@ReferenceMany for type safety and IDE autocompletion.Doctrine\ODM\MongoDB\Mapping\Annotations\Document in your custom base class for shared behavior.@Assert\NotBlank) alongside MongoDB-specific rules.DocumentManager in unit tests to avoid real database dependencies.Field Type Mismatches:
DateTime, ArrayCollection). Avoid PHP native types like array or string without casting.DateTime instead of string for dates.Relationship Direction:
mappedBy/inversedBy in @OneToMany).Index Conflicts:
php artisan doctrine:schema:validate
Collection Attribute:
Collection attribute (PR #6). Use ArrayCollection or array with @Field(type="array") instead.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
Custom Templates: Override the default maker templates by publishing and modifying:
php artisan vendor:publish --tag="mongodb-maker-templates"
Commands:
Extend existing commands (e.g., make:document) by creating a custom command that calls the bundle’s base command and adds logic.
Field Types:
Add custom field types by implementing Doctrine\ODM\MongoDB\Mapping\Driver\Driver and registering it in the bundle’s configuration.
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.
How can I help you explore Laravel packages today?