mongodb/laravel-mongodb
MongoDB integration for Laravel Eloquent and the Query Builder, extending the native Laravel API to work with MongoDB. Official mongodb/laravel-mongodb package (formerly jenssegers), compatible with Laravel 10.x.
$lookup in aggregation pipelines) but may introduce performance trade-offs for heavily relational data.extends Model with extends Document, with identical method signatures (e.g., find(), create()). Migration effort is low for teams already using Eloquent.telescope for query monitoring and horizon for job processing.$lookup pipelines, which can impact read performance.$set operations or third-party tools (e.g., laravel-mongodb-schema).pecl install mongodb).deleted_at field.Document?hasMany, belongsTo). Identify candidates for denormalization or $lookup pipelines.composer require mongodb/laravel-mongodb
.env:
DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DATABASE=your_db
DB_USERNAME=your_user
DB_PASSWORD=your_password
php artisan vendor:publish --provider="MongoDB\Laravel\MongoDBServiceProvider" --tag="config"
use Illuminate\Database\Eloquent\Model; with use MongoDB\Laravel\Eloquent\Model;.Document instead of Model:
use MongoDB\Laravel\Eloquent\Model as Document;
class User extends Document { ... }
$lookup for joins).DB::raw('JSON_EXTRACT')) with MongoDB equivalents (e.g., $elemMatch, $arrayElemAt).$set operations for schema changes.hasOne, belongsToMany), accessors/mutators, and events.where(), orderBy(), groupBy(), and raw MongoDB queries via $query->raw(['$match' => [...]]).User, Product) with careful attention to relationships.$lookup pipelines for complex joins or denormalize data where feasible.laravel-mongodb-schema for validation rules.mongodump, Atlas backups). Integrate with Laravel’s backup system via custom commands.explain() plans).How can I help you explore Laravel packages today?