Skip to content
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-34101-create-bulk-operations-page #948

Merged
26 changes: 13 additions & 13 deletions source/code-snippets/crud/bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ const uri = '<connection string>'; // Add your MongoDB connection string here

// begin-sample-data
const docs = [
{ title: "Inception", year: 2010, rated: "PG-13", released: "2010-07-16" },
{ title: "Interstellar", year: 2014, rated: "PG-13", released: "2014-11-07" },
{ title: "The Dark Knight", year: 2008, rated: "PG-13", released: "2008-07-18" },
{ title: "Tenet", year: 2020, rated: "PG-13", released: "2020-09-03" }
{title: "Inception", year: 2010, rated: "PG-13", released: "2010-07-16"},
gmiller-mdb marked this conversation as resolved.
Show resolved Hide resolved
{title: "Interstellar", year: 2014, rated: "PG-13", released: "2014-11-07"},
{title: "The Dark Knight", year: 2008, rated: "PG-13", released: "2008-07-18"},
{title: "Tenet", year: 2020, rated: "PG-13", released: "2020-09-03"}
];
// end-sample-data

// begin-insert
const bulkOps = [
{ insertOne: { document: { title: "Inception", year: 2010, rated: "PG-13", released: "2010-07-16" } } },
{ insertOne: { document: { title: "Interstellar", year: 2014, rated: "PG-13", released: "2014-11-07" } } },
{ insertOne: { document: { title: "The Dark Knight", year: 2008, rated: "PG-13", released: "2008-07-18" } } },
{ insertOne: { document: { title: "Tenet", year: 2020, rated: "PG-13", released: "2020-09-03" } } }
{insertOne: { document: { title: "Inception", year: 2010, rated: "PG-13", released: "2010-07-16" } }},
{insertOne: { document: { title: "Interstellar", year: 2014, rated: "PG-13", released: "2014-11-07" } }},
{insertOne: { document: { title: "The Dark Knight", year: 2008, rated: "PG-13", released: "2008-07-18" } }},
{insertOne: { document: { title: "Tenet", year: 2020, rated: "PG-13", released: "2020-09-03" } }}
];

await movies.bulkWrite(bulkOps);
Expand All @@ -38,8 +38,8 @@ const uri = '<connection string>'; // Add your MongoDB connection string here

// Inserting additional movies
const additionalMovies = [
{ title: "Dunkirk", year: 2017, rated: "PG-13", released: "2017-07-21" },
{ title: "Memento", year: 2000, rated: "R", released: "2000-09-05" }
{title: "Dunkirk", year: 2017, rated: "PG-13", released: "2017-07-21"},
{title: "Memento", year: 2000, rated: "R", released: "2000-09-05"}
];
await movies.insertMany(additionalMovies);

Expand All @@ -62,7 +62,7 @@ const uri = '<connection string>'; // Add your MongoDB connection string here
}
];

const result2 = await movies.bulkWrite(replaceOperations);
const replace_result = await movies.bulkWrite(replaceOperations);
// end-replace


Expand All @@ -83,7 +83,7 @@ const uri = '<connection string>'; // Add your MongoDB connection string here
}
];

const result3 = await movies.bulkWrite(updateOperations);
const update_result = await movies.bulkWrite(updateOperations);

console.log(`Matched documents: ${result3.matchedCount}`);
console.log(`Modified documents: ${result3.modifiedCount}`);
Expand All @@ -105,7 +105,7 @@ const uri = '<connection string>'; // Add your MongoDB connection string here
];


const result4 = await movies.bulkWrite(deleteOperations);
const delete_result = await movies.bulkWrite(deleteOperations);

console.log(`Deleted documents: ${result4.deletedCount}`);
// end-delete
Expand Down
2 changes: 1 addition & 1 deletion source/fundamentals/crud/write-operations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Write Operations
Modify </fundamentals/crud/write-operations/modify>
Update Arrays </fundamentals/crud/write-operations/embedded-arrays>
Upsert </fundamentals/crud/write-operations/upsert>
Bulk </fundamentals/crud/write-operations/bulk>
Bulk Operations </fundamentals/crud/write-operations/bulk>

- :doc:`/fundamentals/crud/write-operations/insert`
- :doc:`/fundamentals/crud/write-operations/pkFactory`
Expand Down
64 changes: 32 additions & 32 deletions source/fundamentals/crud/write-operations/bulk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
perform **bulk operations**.

Bulk operations perform multiple write operations against one or more
collections within a database. In MongoDB, you refer to a collection by combining

Check failure on line 20 in source/fundamentals/crud/write-operations/bulk.txt

View workflow job for this annotation

GitHub Actions / TDBX Vale rules

[vale] reported by reviewdog 🐶 [MongoDB.ConciseTerms] 'see' is preferred over 'refer to'. Raw Output: {"message": "[MongoDB.ConciseTerms] 'see' is preferred over 'refer to'.", "location": {"path": "source/fundamentals/crud/write-operations/bulk.txt", "range": {"start": {"line": 20, "column": 48}}}, "severity": "ERROR"}
the database name and the collection name in the format ``<database>.<collection>``.
Since you perform bulk operations on a ``MongoClient`` instance, you can perform
bulk operations against any database and colllection in the cluster accessed by
bulk operations against any database and collection in the cluster accessed by
your client.

Bulk operations help reduce the number of calls to the server. Instead of sending
Expand All @@ -29,15 +29,15 @@
This guide includes the following sections:

- :ref:`node-bulk-sample-data` presents the sample data that is used by the
gmiller-mdb marked this conversation as resolved.
Show resolved Hide resolved
bulk operation examples
bulk operation examples.
- :ref:`node-bulk-operation-types` describes how to use different bulk operation
types to perform bulk insert, replace, update, and delete operations
types to perform bulk insert, replace, update, and delete operations.
- :ref:`node-bulk-return-type` describes the return object that results from your
bulk write operations.
- :ref:`node-bulk-handle-exceptions` describes the exceptions that occur if
any of the operations in a bulk write operation fail.
- :ref:`node-bulk-addtl-info` provides links to resources and API documentation for
types and methods mentioned in this guide
types and methods mentioned in this guide.

.. important::

Expand All @@ -56,7 +56,7 @@
in the ``movies`` collection in the ``sample_mflix`` database:

.. literalinclude:: /code-snippets/crud/bulk.js
:language: node.js
:language: javascript
:dedent:
:start-after: begin-sample-data
:end-before: end-sample-data
Expand Down Expand Up @@ -108,7 +108,7 @@
.. input:: /code-snippets/crud/bulk.js
:start-after: begin-insert
:end-before: end-insert
:language: node.js
:language: javascript
:dedent:

.. output::
Expand Down Expand Up @@ -147,7 +147,7 @@
* - ``collation``
- | (Optional) The collation to use when sorting results. To learn more
about collations, see the :ref:`node-fundamentals-collations` guide.
| Type: ``String or Object``
| Type: ``String`` or ``Object``

* - ``hint``
- | (Optional) The index to use for the operation. To learn more about
Expand All @@ -174,7 +174,7 @@
.. input:: /code-snippets/crud/bulk.js
:start-after: begin-replace
:end-before: end-replace
:language: node.js
:language: javascript
:dedent:

.. output::
Expand Down Expand Up @@ -251,7 +251,7 @@
.. input:: /code-snippets/crud/bulk.js
:start-after: begin-update
:end-before: end-update
:language: node.js
:language: javascript
:dedent:

.. output::
Expand All @@ -266,7 +266,7 @@
~~~~~~

To perform a bulk delete operation, create a ``DeleteOneModel`` or ``DeleteManyModel``
instance for each delete operation. Then, pass an array of thesemodels to the
instance for each delete operation. Then, pass an array of these models to the
``bulkWrite()`` method. A ``DeleteOneModel`` deletes only one document that matches
a filter, while a ``DeleteManyModel`` deletes all documents that match a filter.

Expand Down Expand Up @@ -304,7 +304,7 @@
This example performs the following actions:

- Specifies a ``DeleteOneModel`` and a ``DeleteManyModel`` instance in an array.
These modelscontain instructions to delete documents representing movies in the
These models contain instructions to delete documents representing movies in the
``movies`` collection.
- Passes the array of models to the ``bulkWrite()`` method.
- Prints the number of deleted documents.
Expand All @@ -314,7 +314,7 @@
.. input:: /code-snippets/crud/bulk.js
:start-after: begin-delete
:end-before: end-delete
:language: node.js
:language: javascript
:dedent:

.. output::
Expand All @@ -328,8 +328,8 @@
Return Type
-----------

The ``bulkWrite()`` method returns a ``BulkWriteResult`` object from which you can
access information about your bulk operation.
The ``bulkWrite()`` method returns a ``BulkWriteResult`` object, which provides
information about your bulk operation.

The ``BulkWriteResult`` object has the following fields:

Expand Down Expand Up @@ -360,24 +360,24 @@

* - ``message``
- | The error message.
| Data Type: ``String``
| Type: ``String``

* - ``writeErrors``
- | An array of errors that occured during the bulk write operation.
| Data Type: ``BulkWriteError[]``
| Type: ``BulkWriteError[]``

* - ``writeConcernErrors``
- | Write concern errors that occured during execution of the bulk write operation.
| Data Type: ``WriteConnectionError[]``
| Type: ``WriteConnectionError[]``

* - ``result``
- | The results of any successful operations performed before the exception was
thrown.
| Data Type: ``BulkWriteResult[]``
| Type: ``BulkWriteResult[]``

* - ``err``
- | The underlying error object, which may contain more details.
| Data Type: ``Error``
| Type: ``Error``

.. _node-bulk-addtl-info:

Expand All @@ -394,16 +394,16 @@
To learn more about any of the methods or types discussed in this
guide, see the following API documentation:

- `BulkWrite() </https://mongodb.github.io/node-mongodb-native/6.12/classes/Collection.html#bulkWrite>`__
- `ClientBulkWriteResult <https://mongodb.github.io/node-mongodb-native/6.12/classes/BulkWriteResult.html>`__
- `InsertOneModel <https://mongodb.github.io/node-mongodb-native/6.12/classes/OrderedBulkOperation.html#insert>`__
- `InsertOne <https://mongodb.github.io/node-mongodb-native/6.12/classes/Collection.html#insertOne>`__
- `ReplaceOne <https://mongodb.github.io/node-mongodb-native/6.12/classes/Collection.html#replaceOne>`__
- `ReplaceOneModel <https://mongodb.github.io/node-mongodb-native/6.12/interfaces/ReplaceOneModel.html>`__
- `UpdateOne <https://mongodb.github.io/node-mongodb-native/6.12/classes/Collection.html#updateOne>`__
- `UpdateMany <https://mongodb.github.io/node-mongodb-native/6.12/classes/Collection.html#updateMany>`__
- `UpdateOneModel <https://mongodb.github.io/node-mongodb-native/6.12/interfaces/UpdateOneModel.html>`__
- `DeleteOne <https://mongodb.github.io/node-mongodb-native/6.12/classes/Collection.html#deleteOne>`__
- `DeleteMany <https://mongodb.github.io/node-mongodb-native/6.12/classes/Collection.html#deleteMany>`__
- `DeleteOneModel <https://mongodb.github.io/node-mongodb-native/6.12/interfaces/DeleteOneModel.html>`__
- `ClientBulkWriteException <https://mongodb.github.io/node-mongodb-native/6.12/classes/MongoClientBulkWriteExecutionError.html>`__
- `BulkWrite() <{+api+}/classes/Collection.html#bulkWrite>`__
- `ClientBulkWriteResult <{+api+}/classes/BulkWriteResult.html>`__
gmiller-mdb marked this conversation as resolved.
Show resolved Hide resolved
- `InsertOneModel <{+api+}/classes/OrderedBulkOperation.html#insert>`__
- `InsertOne <{+api+}/classes/Collection.html#insertOne>`__
- `ReplaceOne <{+api+}/classes/Collection.html#replaceOne>`__
- `ReplaceOneModel <{+api+}/interfaces/ReplaceOneModel.html>`__
- `UpdateOne <{+api+}/classes/Collection.html#updateOne>`__
- `UpdateMany <{+api+}/classes/Collection.html#updateMany>`__
- `UpdateOneModel <{+api+}/interfaces/UpdateOneModel.html>`__
- `DeleteOne <{+api+}/classes/Collection.html#deleteOne>`__
- `DeleteMany <{+api+}/classes/Collection.html#deleteMany>`__
- `DeleteOneModel <{+api+}/interfaces/DeleteOneModel.html>`__
- `ClientBulkWriteException <{+api+}/classes/MongoClientBulkWriteExecutionError.html>`__
gmiller-mdb marked this conversation as resolved.
Show resolved Hide resolved
Loading