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

updateOrCreate -> createOrFirst doesn't work as expected

Open Boevsson opened this issue 1 month ago • 2 comments

  • Laravel-mongodb Version: 4.2
  • PHP Version: 8.3.4
  • Database Driver & Version: mongod 5.0 / 7.0

Description:

Steps to reproduce

  1. $id = $request->get('id') ?? null; // in the case id is null
  2. Do Model::updateOrCreate(['_id' => $id], $data);

Expected behaviour

A new record should be created with the given data and a generated _id.

Actual behaviour

It queries the first record from the collection and updates it.

This works fine when using the package 4.0 because the createOrFirst is not overriden there in the Mongo Builder class

Boevsson avatar May 14 '24 11:05 Boevsson