Skip to content

DOCSP-35980: Insert One usage example #2826

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 9 commits into from
Apr 18, 2024
Merged

DOCSP-35980: Insert One usage example #2826

merged 9 commits into from
Apr 18, 2024

Conversation

norareidy
Copy link
Contributor

@norareidy norareidy commented Apr 4, 2024

Adds a usage example showing how to insert a document.
JIRA - https://jira.mongodb.org/browse/DOCSP-35980
Staging - https://preview-mongodbnorareidy.gatsbyjs.io/laravel/DOCSP-35980-staging/usage-examples/insertOne/

Checklist

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

@GromNaN GromNaN added the docs label Apr 5, 2024
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

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

lgtm with a few comments!

Comment on lines 20 to 21
You can insert a document into a collection by calling the ``create()`` method on
an Eloquent model or on a query builder.
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
You can insert a document into a collection by calling the ``create()`` method on
an Eloquent model or on a query builder.
You can insert a document into a collection by calling the ``create()`` method on
an Eloquent model or query builder.

Comment on lines 64 to 65
For instructions on editing your Laravel application to run the usage example, see the
:ref:`Usage Example landing page <laravel-usage-examples>`.
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
For instructions on editing your Laravel application to run the usage example, see the
:ref:`Usage Example landing page <laravel-usage-examples>`.
To learn how to edit your Laravel application to run the usage example, see the
:ref:`Usage Example landing page <laravel-usage-examples>`.

.. tip::

You can also use the ``save()`` or ``insert()`` methods to insert a document into a collection.
To learn more about insert operations, see the :ref:`laravel-fundamentals-insert-documents` section
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: will this be merged only after write operations is merged? Link is broken as of now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'll wait until after write operations is merged

@norareidy norareidy marked this pull request as ready for review April 9, 2024 15:58
@norareidy norareidy requested a review from a team as a code owner April 9, 2024 15:58
@norareidy norareidy requested a review from alcaeus April 9, 2024 15:58
@GromNaN GromNaN requested review from GromNaN and removed request for alcaeus April 9, 2024 18:45
Comment on lines +23 to +27
$movie = Movie::create([
'title' => 'Marriage Story',
'year' => 2019,
'runtime' => 136,
]);
Copy link
Member

Choose a reason for hiding this comment

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

This example could be completed by the more expressive form (if anyone need to update the $movie model before saving):

$movie = new Movie([
    'title' => 'Marriage Story',
    'year' => 2019,
    'runtime' => 136,
]);
$movie->save();

Copy link
Contributor

Choose a reason for hiding this comment

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

@GromNaN Would you recommend replacing the create() example with one that shows save()? If save() seems more common and helpful, we could update the example to show that method of inserting a single document instead.

Copy link
Member

Choose a reason for hiding this comment

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

No, Movie::create([...]) is the most common way to create a model.

There is also Movie::createOrFirst() that can be used (using findOneAndUpdate with upsert)

@norareidy norareidy requested a review from a team as a code owner April 17, 2024 19:38
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

LGTM as this.

@ccho-mongodb ccho-mongodb merged commit 01dd49f into mongodb:4.1 Apr 18, 2024
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.

4 participants