Convert Figma logo to code with AI

mongodb logolaravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

6,987
1,423
6,987
140

Top Related Projects

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Quick Overview

MongoDB Laravel is a Laravel package that provides an Eloquent-like model and query builder for MongoDB. It allows developers to use MongoDB in Laravel applications with a familiar syntax, making it easier to integrate MongoDB into existing Laravel projects or build new ones with MongoDB as the primary database.

Pros

  • Seamless integration with Laravel's Eloquent ORM
  • Supports many Eloquent features like relationships, query scopes, and model events
  • Provides a query builder with MongoDB-specific operations
  • Allows easy switching between SQL and MongoDB databases in Laravel projects

Cons

  • Some advanced MongoDB features may not be fully supported
  • Performance might be slightly lower compared to using native MongoDB drivers
  • Learning curve for developers not familiar with MongoDB concepts
  • Limited support for complex aggregation pipelines

Code Examples

  1. Defining a MongoDB model:
use Jenssegers\Mongodb\Eloquent\Model;

class User extends Model
{
    protected $connection = 'mongodb';
    protected $collection = 'users';

    protected $fillable = ['name', 'email'];
}
  1. Querying MongoDB data:
$users = User::where('age', '>', 30)
             ->orderBy('name', 'asc')
             ->take(10)
             ->get();
  1. Using MongoDB-specific operators:
$users = User::where('skills', 'elemMatch', ['name' => 'php', 'level' => 'expert'])
             ->get();
  1. Performing aggregations:
$result = User::raw(function($collection) {
    return $collection->aggregate([
        ['$group' => ['_id' => '$city', 'count' => ['$sum' => 1]]],
        ['$sort' => ['count' => -1]]
    ]);
});

Getting Started

  1. Install the package via Composer:

    composer require jenssegers/mongodb
    
  2. Add the MongoDB service provider in config/app.php:

    Jenssegers\Mongodb\MongodbServiceProvider::class,
    
  3. Configure MongoDB connection in config/database.php:

    'mongodb' => [
        'driver' => 'mongodb',
        'host' => env('MONGO_DB_HOST', 'localhost'),
        'port' => env('MONGO_DB_PORT', 27017),
        'database' => env('MONGO_DB_DATABASE', 'your_database'),
        'username' => env('MONGO_DB_USERNAME', ''),
        'password' => env('MONGO_DB_PASSWORD', ''),
    ],
    
  4. Create MongoDB models by extending Jenssegers\Mongodb\Eloquent\Model.

Competitor Comparisons

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Pros of laravel-mongodb

  • More active development and frequent updates
  • Better integration with Laravel's Eloquent ORM
  • Larger community and more extensive documentation

Cons of laravel-mongodb

  • Slightly steeper learning curve for developers new to MongoDB
  • May require more configuration for complex queries

Code Comparison

laravel-mongodb:

use Jenssegers\Mongodb\Eloquent\Model;

class User extends Model
{
    protected $connection = 'mongodb';
}

mongodb/laravel-mongodb:

use MongoDB\Laravel\Eloquent\Model;

class User extends Model
{
    protected $connection = 'mongodb';
}

Key Differences

  • laravel-mongodb offers more advanced features like geospatial indexing and aggregation pipelines
  • mongodb/laravel-mongodb provides a simpler implementation but with fewer MongoDB-specific features
  • laravel-mongodb has more frequent releases and bug fixes
  • mongodb/laravel-mongodb may be easier to set up for basic MongoDB usage in Laravel projects

Community and Support

  • laravel-mongodb has a larger user base and more active GitHub discussions
  • mongodb/laravel-mongodb has fewer contributors but still maintains a stable codebase

Performance

  • Both packages offer similar performance for basic CRUD operations
  • laravel-mongodb may have a slight edge in complex queries due to its more extensive feature set

Compatibility

  • Both packages support recent versions of Laravel and MongoDB
  • laravel-mongodb tends to update more quickly for new Laravel releases

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Laravel MongoDB

Latest Stable Version Total Downloads Build Status

This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library extends the original Laravel classes, so it uses exactly the same methods.

This package was renamed to mongodb/laravel-mongodb because of a transfer of ownership to MongoDB, Inc. It is compatible with Laravel 10.x. For older versions of Laravel, please refer to the old versions.

Documentation

Release Integrity

Releases are created automatically and the resulting release tag is signed using the PHP team's GPG key. To verify the tag signature, download the key and import it using gpg:

gpg --import php-driver.asc

Then, in a local clone, verify the signature of a given tag (e.g. 4.4.0):

git show --show-signature 4.4.0

[!NOTE] Composer does not support verifying signatures as part of its installation process.

Reporting Issues

Think you’ve found a bug in the library? Want to see a new feature? Please open a case in our issue management tool, JIRA:

  • Create an account and login.
  • Navigate to the PHPORM project.
  • Click Create - Please provide as much information as possible about the issue type and how to reproduce it.

Note: All reported issues in JIRA project are public.

For general questions and support requests, please use one of MongoDB's Technical Support channels.

Security Vulnerabilities

If you've identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions in Create a Vulnerability Report.

Development

Development is tracked in the PHPORM project in MongoDB's JIRA. Documentation for contributing to this project may be found in CONTRIBUTING.md.