getting command find requires authentication from mongodb in laravel project

94 Views Asked by At

I have a project in laravel 8 where i have integrated mongodb. project is fetching data from 2 databases. for security perpose i have enabled the authorization in mongo.conf.

when i try to fetch data using my local machine i am getting data and mongodb is working as expected but on server i am getting command find requires authentication

i have created user with different roles and access to make it work and i am getting data with mongo shell and mongodb compass but not able to get data with laravel project.

I have verified the values which i am using the values.

I also tried to make it work with mongodb uri but getting the same error

1

There are 1 best solutions below

0
On

If you are using Laravel ,and all credentials are fine, and you check that you can access the mongodb with a very simple snippet like this:

<?php

use MongoDB\Client; // Used extension

$mongo = new MongoDB\Driver\Manager('mongodb://<username>:<no_more_war_in_gaza>@mongodb:27017');
$query = new MongoDB\Driver\Query(array('age' => 30));
$cursor = $mongo->executeQuery('ts.testCollection',$query);
print_r($cursor->toArray());

then maybe your problem is cache. Try this:

php artisan cache:clear
php artisan config:clear