laravellaravel-mongodb

increment or decrement without using laravel methods mangodb jassengers


I want to update documents and decrement specific column value. it is possible to use Model::where('','')->update(['count' => \DB::raw('count- 1')]); i'm using jenssegers/laravel-mongodb package.

I want decrement and update documents values together.

$result= Source::where('')
         ->where('');
$result->decrement('count');
$result->update([
   'column' => true,
]);

This code decrement count value but can not update column values.


Solution

  • i found it from laravel doc updated column value pass 3rd parameter as array in decrement method

    Model::where('', null)
            ->where('', '')
            ->decrement('count', 1, [
                'column1' => value1,
                'column2' => value2,
                'column3' => value3,
            ]);