Skip to content

DOCSP-35946 write operations arrays #2825

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

Conversation

ccho-mongodb
Copy link
Contributor

@ccho-mongodb ccho-mongodb commented Apr 4, 2024

JIRA:
https://jira.mongodb.org/browse/DOCSP-35946

Staging:

Update Arrays in a Document

Note:

This PR is stacked on the Modify documents PR.

This is the third of three tickets that document the update sections in "Fundamentals > Write Operations". The final section of the "Fundamentals > Write Operations" will be the Delete Documents section.

Relevant changes:

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

Copy link
Contributor

@norareidy norareidy left a comment

Choose a reason for hiding this comment

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

LGTM + some comments!

Comment on lines 329 to 331
- Add values to an array
- Remove values from an array
- Update the value of an array element
Copy link
Contributor

Choose a reason for hiding this comment

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

S: linking to each section here would be helpful

Suggested change
- Add values to an array
- Remove values from an array
- Update the value of an array element
- :ref:`Add values to an array <laravel-modify-documents-add-array-values>`
- :ref:`Remove values from an array <laravel-modify-documents-remove-array-values>`
- :ref:`Update the value of an array element <laravel-modify-documents-update-array-values>`

Copy link
Contributor Author

@ccho-mongodb ccho-mongodb Apr 4, 2024

Choose a reason for hiding this comment

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

Thanks -- I was undecided about this, but if you think it's helpful, I'll add them for these examples and the ones from other PRs.

[<values>], // array or single value to add
unique: true); // whether to skip existing values

The following example shows how to add the value ``baroque`` to
Copy link
Contributor

Choose a reason for hiding this comment

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

S: add quotes

Suggested change
The following example shows how to add the value ``baroque`` to
The following example shows how to add the value ``'baroque'`` to

Copy link
Contributor Author

@ccho-mongodb ccho-mongodb Apr 4, 2024

Choose a reason for hiding this comment

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

Good catch! Started a discussion on Slack regarding whether to use single or double quotes to format string values (to address the rest of the similar comments).

:copyable: false

YourModel::where(<match criteria>)
->push(
Copy link
Contributor

Choose a reason for hiding this comment

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

I: I think this should be pull()

Suggested change
->push(
->pull(

Comment on lines +409 to +410
The following example shows how to remove array values ``"classical"`` and
``"dance-pop"`` from the ``genres`` array field. Click the
Copy link
Contributor

Choose a reason for hiding this comment

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

S: [nit] since single quotes are used in the code:

Suggested change
The following example shows how to remove array values ``"classical"`` and
``"dance-pop"`` from the ``genres`` array field. Click the
The following example shows how to remove array values ``'classical'`` and
``'dance-pop'`` from the ``genres`` array field. Click the

Comment on lines +460 to +461
The following example shows how to replace the array value ``"dance-pop"``
with ``"contemporary"`` in the ``genres`` array field. Click the
Copy link
Contributor

Choose a reason for hiding this comment

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

S: same comment about single quotes as above:

Suggested change
The following example shows how to replace the array value ``"dance-pop"``
with ``"contemporary"`` in the ``genres`` array field. Click the
The following example shows how to replace the array value ``'dance-pop'``
with ``'contemporary'`` in the ``genres`` array field. Click the

Comment on lines 348 to 349
in a MongoDB document. You can pass one or more values to add and set the
optional parameter ``unique`` to ``true`` to skip adding any values
Copy link
Contributor

Choose a reason for hiding this comment

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

I: it doesn't seem accurate to say that setting unique to true skips adding "any values in the array" - maybe you could add "duplicate"?

S: I also think you can clarify this sentence a little by adding a comma:

Suggested change
in a MongoDB document. You can pass one or more values to add and set the
optional parameter ``unique`` to ``true`` to skip adding any values
in a MongoDB document. You can pass one or more values to add to the array, and you can set the
optional parameter ``unique`` to ``true`` to skip adding any duplicate values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I think I missed that when revising this sentence multiple times.

@ccho-mongodb ccho-mongodb marked this pull request as ready for review April 5, 2024 14:12
@ccho-mongodb ccho-mongodb requested a review from a team as a code owner April 5, 2024 14:12
@ccho-mongodb ccho-mongodb requested review from GromNaN and removed request for a team April 5, 2024 14:12
@GromNaN GromNaN added the docs label Apr 5, 2024
@ccho-mongodb ccho-mongodb merged commit acec97f into mongodb:4.1-base-docs-write-operations Apr 8, 2024
@ccho-mongodb ccho-mongodb deleted the DOCSP-35946-write-operations-arrays branch April 8, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants