laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

how to update only one record ?

Open samerzaki opened this issue 1 year ago • 2 comments

I have used both of those: Product::limit(1)->update(['xxx' => 'yyy']); and

Product::update(['xxx' => 'yyy'], ['multi' => 0, 'multiple' => 0]); and none of them worked

samerzaki avatar Aug 12 '22 20:08 samerzaki

Good morning sir

TochukwuGabrielAgu avatar Sep 05 '22 07:09 TochukwuGabrielAgu

Hi @samerzaki you only want to update one record, no matter which is in the DB?

if this is the case this should help you:

$Product = Product::take(1)->skip(rand(0,$noOfProduct-1))->first();
$Product->xxx = "yyy";
$Product->save()

LJMartinez07 avatar Sep 15 '22 16:09 LJMartinez07