Skip to content

Commit 5d100e4

Browse files
DOCSP-14364 updating CRUDInsert (#171)
* clarified examples on the page
1 parent 1e5df84 commit 5d100e4

File tree

1 file changed

+20
-15
lines changed
  • source/fundamentals/crud/write-operations

1 file changed

+20
-15
lines changed

source/fundamentals/crud/write-operations/insert.txt

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,28 @@ documents from a collection in your MongoDB database.
1313
Insert
1414
------
1515

16-
If you want to add new documents to a collection, you can use
17-
the ``insertOne()`` or the ``insertMany()`` method. These methods accept
16+
To add new documents to a collection, you can use
17+
the ``insertOne()`` or the ``insertMany()`` methods. These methods accept
1818
single or multiple documents, respectively. The driver automatically
1919
generates a unique ``_id`` field for documents unless specified.
2020

21-
You can specify the document to be inserted by the ``insertOne()`` write
22-
operation in a JSON object as follows:
21+
The following examples use a collection called ``pizzaCollection``,
22+
which contains documents with the name and shape of a pizza.
23+
24+
Insert a Document Example
25+
~~~~~~~~~~~~~~~~~~~~~~~~~
26+
27+
You can specify a document in a JSON object as follows:
2328

2429
.. code-block:: javascript
2530

2631
const pizzaDocument = {
2732
name: "Neapolitan pizza",
28-
shape: "round",
29-
toppings: [ "San Marzano tomatoes", "mozzarella di bufala cheese" ],
33+
shape: "round"
3034
};
3135

32-
To insert the document into the collection reference ``pizzaCollection``,
33-
specify the document as the first parameter of your call to the
34-
``insertOne()`` method as shown below:
36+
To insert this document into ``pizzaCollection``, pass ``pizzaDocument``
37+
as the first parameter to the ``insertOne()`` method as shown below:
3538

3639
.. code-block:: javascript
3740

@@ -47,20 +50,22 @@ You can print the number of documents inserted by accessing the
4750
For a runnable example, see the :doc:`insertOne() </usage-examples/insertOne>`
4851
usage example.
4952

50-
You can specify the documents to be inserted by the ``insertMany()`` write
51-
operation in an array of JSON objects as follows:
53+
Insert Multiple Documents Example
54+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55+
56+
You can specify multiple documents in an array of JSON objects as follows:
5257

5358
.. code-block:: javascript
5459

5560
const pizzaDocuments = [
5661
{ name: "Sicilian pizza", shape: "square" },
5762
{ name: "New York pizza", shape: "round" },
58-
{ name: "Grandma pizza", shape: "square" },
63+
{ name: "Grandma pizza", shape: "square" }
5964
];
6065

61-
To insert the array of documents into the collection reference
62-
``pizzaCollection``, specify the array as the first parameter of your call
63-
to the ``insertMany()`` method as shown below:
66+
To insert these documents into ``pizzaCollection``, pass
67+
``pizzaDocuments`` as the first parameter to the ``insertMany()`` method
68+
as shown below:
6469

6570
.. code-block:: javascript
6671

0 commit comments

Comments
 (0)