Facing problem when reconnecting mongo
I have a team of employees '
I am creating a new mongo connection using the following code
$mongoObject = DB::connection('mongodb')->collection('employees');
//fetch employee by employee id
$employee = $mongoObject->where('employee_id', $input['employee_id'])->first();
//Fetch all employees
$employees = $mongoObject->get();
Now my problem is that I got the first answer correctly, but when I tried to fetch all employees using the same mongo connection, it only gives one entry. From my understanding, this is not clearing the conditions after using -> first () eloquent.
Is there a way to reuse the same mongo connection with eloquent methods?
Thank.
+3
source to share
1 answer
After calling first (), the limit is set to 1, so get returns one record.
The following code works: -
$mongoObject = DB::connection('mongodb')->collection('employees');
//fetch employee by employee id
$employee = $mongoObject->where('employee_id', $input['employee_id'])->first();
//Fetch all employees
$employees = $mongoObject->newQuery()->from('employees')->get();
0
source to share