Skip to content

DOCSP-43530: Id field in query results #3149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog
All notable changes to this project will be documented in this file.

## [5.0.0] - next
## [5.0.0] - 2024-09-12

* Remove support for Laravel 10 by @GromNaN in [#3123](https://github.com/mongodb/laravel-mongodb/pull/3123)
* **BREAKING CHANGE** Use `id` as an alias for `_id` in commands and queries for compatibility with Eloquent packages by @GromNaN in [#3040](https://github.com/mongodb/laravel-mongodb/pull/3040) and [#3136](https://github.com/mongodb/laravel-mongodb/pull/3136)
Expand Down
5 changes: 3 additions & 2 deletions docs/query-builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ the value of the ``title`` field is ``"Back to the Future"``:

You can use the ``id`` alias in your queries to represent the
``_id`` field in MongoDB documents, as shown in the preceding
code. When you run a find operation using the query builder, {+odm-short+}
automatically converts between ``id`` and ``_id``. This provides better
code. When you run a find operation using the query builder, the {+odm-short+}
automatically converts between ``id`` and ``_id``. In query results,
the ``_id`` field is renamed to ``id``. This provides better
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: avoid using

Suggested change
code. When you run a find operation using the query builder, the {+odm-short+}
automatically converts between ``id`` and ``_id``. In query results,
the ``_id`` field is renamed to ``id``. This provides better
code. When you use the query builder to run a find operation, the {+odm-short+}
automatically converts between ``_id`` and``id`` field names. In query results,
the ``_id`` field is presented as ``id``. This provides better

compatibility with Laravel, as the framework assumes that each record has a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
compatibility with Laravel, as the framework assumes that each record has a
consistency with Laravel, as the framework assumes that each record has a

primary key named ``id`` by default.

Expand Down
7 changes: 4 additions & 3 deletions docs/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ This library version introduces the following breaking changes:
date classes, applying the default timezone.

- ``id`` is an alias for the ``_id`` field in MongoDB documents, and the library
automatically converts between ``id`` and ``_id`` when querying data. Because
of this behavior, you cannot have two separate ``id`` and ``_id`` fields in your
documents.
automatically converts between ``id`` and ``_id`` when querying data. The query
result object includes an ``id`` field to represent the document's ``_id`` field.
Because of this behavior, you cannot have two separate ``id`` and ``_id`` fields
in your documents.

- Removes support for the ``$collection`` property. The following code shows
how to assign a MongoDB collection to a variable in your ``User`` class in
Expand Down
Loading