Skip to content

Updating a date field using update([]) does not convert it to mongo date. #2177

Description

@fidan-mkdir
  • Laravel-mongodb Version: 3.6.6
  • PHP Version: 7.3
  • Database Driver & Version:

Description:

Updating documents with the ->update() method saves Carbon dates as Object instead of Date in the database. Doing the same using ->save() on a model works fine. Yes, the models have the property registered as a date in the $dates array.

Steps to reproduce

  1. Create model with property 'end_date'. Add property to $dates array on the model.
  2. Create date $date = Carbon::parse('2021-01-08 10:00');
  3. Run query: Model::where('match', true)->update(['end_date' => $date]);
  4. Check db.

Expected behaviour

The end_dateshould be saved as a field of type Date instead of Object
image

Actual behaviour

end_date is saved as object
image

Additionally, if you were to do ->update(['end_date' => $date->toIso8601String()]) the date would be saved as a String field

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions