Extend Jenssegers/laravel-mongodb to support transaction function

Overview

Laravel Mongodb (Transactional support)

Introduction

Jensseger's laravel-mongodb extension package is very popular among Laravel developers, but it lacks a transactional feature. mongoDB 4.x supports multi-document transactions. Therefore, this package extends Jenssegers/laravel-mongodb with transactional support.

  1. mongoDB transactions are based on the mongoDB4.x replica set environment. mongoDB
  2. This package depends on Jenssegers/laravel-mongodb, so it needs to be installed first.

Installation

Regarding the use of packages, it is necessary to replace Jenssegers/laravel-mongodb:

Install by composer

composer require imanrjb/laravel-mongodb

Laravel

//Jenssegers\Mongodb\MongodbServiceProvider::class,
ImanRjb\Mongodb\MongodbServiceProvider::class

Lumen

//$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class);
$app->register(ImanRjb\Mongodb\MongodbServiceProvider::class);

$app->withEloquent();

Eloquent

Eloquent only expands on transaction-related content, so it directly replaces Jenssegers/laravel-mongodb

use ImanRjb\Mongodb\Eloquent\Model;

class User extends Model {}
use ImanRjb\Mongodb\Eloquent\Model;

class MyModel extends Model {

    protected $connection = 'mongodb';

}

For more Eloquent documentation see (http://laravel.com/docs/eloquent)

Usage

DB::connection('mongodb')->beginTransaction();

try {
    User::insert($userData);
    UserInfo::insert($userInfoData);
    
    DB::connection('mongodb')->commit();
} catch (\Exception $e) {
    DB::connection('mongodb')->rollBack();
    throw $e;
}
You might also like...
:gem: Simple MySQLi Abstraction Layer + Doctrine/DBAL support

💎 Simple MySQLi Class This is a simple MySQL Abstraction Layer compatible with PHP 7+ that provides a simple and secure interaction with your databas

Support for many missing PostgreSQL specific features
Support for many missing PostgreSQL specific features

Laravel supports many different databases and therefore has to limit itself to the lowest common denominator of all databases. PostgreSQL, however, of

A Laravel package to output a specific sql to your favourite debugging tool. The supported log output is Laravel Telescope, Laravel Log, Ray, Clockwork, Laravel Debugbar and your browser.
A Laravel package to output a specific sql to your favourite debugging tool. The supported log output is Laravel Telescope, Laravel Log, Ray, Clockwork, Laravel Debugbar and your browser.

Laravel showsql A Laravel package to output a specific sql to your favourite debugging tool, your browser or your log file. Use case You often want to

Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster.
Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster.

Laravel Thermite Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster. 🤝 Supporting If you are usin

This project is about import CSV to Laravel with Laravel Excel library.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Illuminate Database The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style OR

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.

Baum Baum is an implementation of the Nested Set pattern for Laravel 5's Eloquent ORM. For Laravel 4.2.x compatibility, check the 1.0.x branch branch

Driver to seamlessly integrate the Backup Manager into Laravel applications.

Laravel Driver for the Database Backup Manager This package pulls in the framework agnostic Backup Manager and provides seamless integration with Lara

Effective tree structures in Laravel 4-5

This is a Laravel 4-8 package for working with trees in relational databases. Laravel 5.7, 5.8, 6.0, 7.0, 8.0 is supported since v5 Laravel 5.5, 5.6 i

Owner
Iman RJ
Iman RJ
MongoDB ORM that includes support for references,embed and multilevel inheritance.

Introduction Features Requirements Installation Setup Database Basic Usage - CRUD Relationship - Reference Relationship - Embed Collection Inheritance

Michael Gan 202 Nov 17, 2022
a php client for distributed transaction framework dtm. 分布式事务管理器dtm的php客户端

a client for distributed transaction manager dtm dtmcli 是分布式事务管理器dtm的客户端sdk dtm分布式事务管理服务 DTM是一款跨语言的开源分布式事务管理器,优雅的解决了幂等、空补偿、悬挂等分布式事务难题。提供了简单易用、高性能、易水平扩

null 29 Jan 7, 2023
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Laravel MongoDB This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library ex

Jens Segers 6.3k Jan 5, 2023
MongoDB PHP library

MongoDB PHP Library This library provides a high-level abstraction around the lower-level PHP driver (mongodb extension). While the extension provides

mongodb 1.5k Dec 31, 2022
Psalm Stubs for doctrine/mongodb-odm library

doctrine-mongodb-psalm-plugin A Doctrine plugin for Psalm (requires Psalm v4). Installation: $ composer require --dev runtothefather/doctrine-mongodb-

Evgeny 6 Jun 15, 2022
Simple MongoDB API for PHP!

SimpleMongo SimpleMongo is a simple API for MongoDB, written in PHP. How to use? First of all, copy SimpleMongo.php into your project and fill the fir

AlicanCopur 9 Jul 19, 2021
Eloquent MongoDB Repository Implementation

Eloquent MongoDB Repository Eloquent MongoDB Repository using nilportugues/repository as foundation, using jenssegers/mongodb. Installation Use Compos

Nil Portugués Calderó 18 Feb 12, 2022
RockMongo is a MongoDB administration tool, written in PHP 5.

Introduction -------------------------------------- RockMongo is a MongoDB administration tool, written in PHP 5, very easy to install and use. Inst

Liu Xiangchao 1k Dec 27, 2022
Migrations for MongoDB based on PHPMongo ODM

PHPMongo Migrator Migrations for MongoDB based on PHPMongo ODM Schema not required in MongoDb, so we dont need to create databases, collections or alt

Sokil 29 Jul 13, 2022
MySQL Load Data Infile Support For Laravel

Laravel Load File ?? A package to help with loading files into MySQL tables. This uses MySQL's LOAD DATA statement to load text files quickly into you

Ellis Green 64 Dec 30, 2022