-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
DOCSP-35980: Insert One usage example #2826
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 with a few comments!
docs/usage-examples/insertOne.txt
Outdated
You can insert a document into a collection by calling the ``create()`` method on | ||
an Eloquent model or on a query builder. |
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.
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. |
docs/usage-examples/insertOne.txt
Outdated
For instructions on editing your Laravel application to run the usage example, see the | ||
:ref:`Usage Example landing page <laravel-usage-examples>`. |
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.
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 |
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.
Q: will this be merged only after write operations is merged? Link is broken as of now
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.
Yeah I'll wait until after write operations is merged
$movie = Movie::create([ | ||
'title' => 'Marriage Story', | ||
'year' => 2019, | ||
'runtime' => 136, | ||
]); |
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.
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();
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.
@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.
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.
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)
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 as this.
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