Skip to content

updateOrCreate -> createOrFirst doesn't work as expected #2945

Closed as not planned
@Boevsson

Description

@Boevsson
  • 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions