I have been having this error on Laravel 11
when I try to upload an Excel document where my database is a MongoDB instance:
Transaction numbers are only allowed on a replica set member or mongos
Steps to reproduce
- I installed
Laravel 11
composer create-project laravel/laravel
- I added
Laravel Mongodb
composer package
composer require mongodb/laravel-mongodb
- I added the
Laravel Excel
composer package
composer require maatwebsite/excel:^3.1
-
Added some User Interface to facilitate the upload of the document. I am trying to upload assets into the web platform.
-
Created an AssetsImport document
php artisan make:import AssetsImport
The part that’s producing the error is on this file,
class AssetsImport implements ToCollection
{
public function collection(Collection $collection)
{
foreach ($collection as $key => $row) {
$asset = Asset::where('asset_no', $row[2])->first();
if($asset) {
continue;
}
// add the upload code
....
}
}
}
The above script is meant to check if there’s an existing Asset. If it’s there, then don’t add it (Continue with the foreach loop).
After checking this similar question, I still could not find a solution for this. Is this the correct way of implementing, and if so, how do I go about solving this error. I don’t have control over the database (there’s a Server Admin) so I cannot just add a replica set. Kindly assist.