-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
DOCSP-35946 write operations arrays #2825
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM + some comments!
- Add values to an array | ||
- Remove values from an array | ||
- Update the value of an array element |
There was a problem hiding this comment.
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
- 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>` |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: add quotes
The following example shows how to add the value ``baroque`` to | |
The following example shows how to add the value ``'baroque'`` to |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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()
->push( | |
->pull( |
The following example shows how to remove array values ``"classical"`` and | ||
``"dance-pop"`` from the ``genres`` array field. Click the |
There was a problem hiding this comment.
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:
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 |
The following example shows how to replace the array value ``"dance-pop"`` | ||
with ``"contemporary"`` in the ``genres`` array field. Click the |
There was a problem hiding this comment.
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:
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 |
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 |
There was a problem hiding this comment.
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:
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 |
There was a problem hiding this comment.
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.
…operations-arrays
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