Skip to content

DOCSP-35949 write operations upsert #2815

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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
grammar fixes
  • Loading branch information
Chris Cho committed Mar 29, 2024
commit d813f23779739daa018c8e5adece573bc41ab2dd
28 changes: 14 additions & 14 deletions docs/fundamentals/write-operations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Overview

In this guide, you can learn how to use {+odm-short+} to perform
**write operations** on your MongoDB collections. Write operations include
inserting, updating, and deleting data based on criteria that you specify.
inserting, updating, and deleting data based on specified criteria.

This guide shows you how to perform the following tasks:

Expand All @@ -38,12 +38,12 @@ Insert Documents
In this section, you can learn how to insert documents into MongoDB collections
from your Laravel application by using the {+odm-long+}.

When you insert the documents, make sure that the data does not violate any
When you insert the documents, ensure the data does not violate any
unique indexes on the collection. When inserting the first document of a
collection or creating a new collection, MongoDB automatically creates a
unique index on the ``_id`` field.

For more information creating indexes on MongoDB collections by using the
For more information on creating indexes on MongoDB collections by using the
Laravel schema builder, see the :ref:`laravel-eloquent-indexes` guide.

This section uses the following example model class to demonstrate how to
Expand All @@ -69,8 +69,8 @@ section.
Insert a Document Examples
~~~~~~~~~~~~~~~~~~~~~~~~~~

The examples in this section show how to use the ``save()`` Eloquent method to
insert an instance of a ``Concert`` model as a MongoDB document.
These examples show how to use the ``save()`` Eloquent method to insert an
instance of a ``Concert`` model as a MongoDB document.

When the ``save()`` method succeeds, the instance on which you called the
method contains the model. If it fails, the instance is assigned a null value.
Expand All @@ -89,8 +89,8 @@ This example code performs the following actions:
:start-after: begin model insert one
:end-before: end model insert one

You can retrieve the inserted document id value by accessing the ``id`` member
of the model as shown in the following code example:
You can retrieve the inserted document's ``_id`` value by accessing the model's
``id`` member as shown in the following code example:

.. literalinclude:: /includes/fundamentals/write-operations/WriteOperationsTest.php
:language: php
Expand All @@ -114,21 +114,21 @@ To learn more about the Carbon PHP API extension, see the
Insert Multiple Documents Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The example in this section show how to use the ``insert()`` Eloquent method
to insert multiple instances of a ``Concert`` model as MongoDB documents.
This bulk insert method reduces the number of calls that your application needs
to make to save the documents.
This example shows how to use the ``insert()`` Eloquent method to insert
multiple instances of a ``Concert`` model as MongoDB documents. This bulk
insert method reduces the number of calls your application needs to make
to save the documents.

When the ``insert()`` method succeeds, the method returns the value ``1``.
If it fails, the method throws an exception.
When the ``insert()`` method succeeds, it returns the value ``1``. If it
fails, it throws an exception.

The example code saves multiple models in a single call by passing them as
an array to ``insert()`` method:

.. note::

This example wraps the dates in the `MongoDB\BSON\UTCDateTime <{+phplib-api+}/class.mongodb-bson-utcdatetime.php>`__
class to convert it to a type that MongoDB can serialize because Laravel
class to convert it to a type MongoDB can serialize because Laravel
skips attribute casting on bulk insert operations.

.. literalinclude:: /includes/fundamentals/write-operations/WriteOperationsTest.php
Expand Down