mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/compatibility/mongodb-laravel-integration
MIT License
7k stars 1.42k forks source link

[Feature Request] Use transaction in AWS DocumentDB #2979

Closed rafael-magno closed 4 months ago

rafael-magno commented 4 months ago

If I use DB::transaction in AWS DocumentDB this error is thrown: "Feature not supported: Causal consistency".

The way I resolved this was by duplicating the ManagesTransactions trait and making the modification to the getSessionOrCreate method, adding a option on startSession method. As shown below:

    private function getSessionOrCreate(): Session
    {
        if ($this->session === null) {
            $this->session = $this->getMongoClient()->startSession(['causalConsistency' => false]);
        }

        return $this->session;
    }

To resolve it definitively, I suggest passing one more parameter ($sessionOptions for example), in the ManagesTransactions::getSessionOrCreate and ManagesTransactions::transaction methods

bisht2050 commented 4 months ago

AWS DocumentDB is a separate implementation from the MongoDB server. DocumentDB has a number of compatibility differences as compared to MongoDB. If your issue isn’t reproducible with an actual MongoDB deployment, there isn’t much we can do to investigate. You could try using a free tier MongoDB Atlas cluster to compare behaviour. For support using DocumentDB I suggest posting on the AWS Forums.