Skip to content

Commit 16eed4e

Browse files
authored
DOCSP 24275 - adding insert operation to survey examples (#1641)
* DOCSP-24275 add insert operation to survey examples * DOCSP-24275 add insert operation to survey examples
1 parent 48e0ec8 commit 16eed4e

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

source/core/index-multikey.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,13 @@ Examples
231231
Index Basic Arrays
232232
~~~~~~~~~~~~~~~~~~
233233

234-
Consider a ``survey`` collection with the following document:
234+
Create a ``survey`` collection with the following document:
235235

236236
.. code-block:: javascript
237237

238-
{ _id: 1, item: "ABC", ratings: [ 2, 5, 9 ] }
238+
db.survey.insertOne(
239+
{ _id: 1, item: "ABC", ratings: [ 2, 5, 9 ] }
240+
)
239241

240242
Create an index on the field ``ratings``:
241243

source/core/multikey-index-bounds.txt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ query that specifies multiple predicates on the array and can use a
3232
:ref:`multikey index <index-type-multikey>` bounds if an
3333
:query:`$elemMatch` joins the predicates.
3434

35-
For example, a collection ``survey`` contains documents with a field
36-
``item`` and an array field ``ratings``:
35+
For example, create a ``survey`` collection that contains documents
36+
with a field ``item`` and an array field ``ratings``:
3737

3838
.. code-block:: javascript
3939

40-
{ _id: 1, item: "ABC", ratings: [ 2, 9 ] }
41-
{ _id: 2, item: "XYZ", ratings: [ 4, 3 ] }
40+
db.survey.insertMany(
41+
[
42+
{ _id: 1, item: "ABC", ratings: [ 2, 9 ] },
43+
{ _id: 2, item: "XYZ", ratings: [ 4, 3 ] }
44+
]
45+
)
4246

4347
Create a :ref:`multikey index <index-type-multikey>` on the ``ratings``
4448
array:
@@ -106,13 +110,18 @@ Compound Index on an Array Field
106110

107111
Consider a compound multikey index; i.e. a :ref:`compound index
108112
<index-type-compound>` where one of the indexed fields is an array. For
109-
example, a collection ``survey`` contains documents with a field
113+
example, create a ``survey`` collection that contains documents with a field
110114
``item`` and an array field ``ratings``:
111115

112116
.. code-block:: javascript
113117

114-
{ _id: 1, item: "ABC", ratings: [ 2, 9 ] }
115-
{ _id: 2, item: "XYZ", ratings: [ 4, 3 ] }
118+
db.survey.insertMany(
119+
[
120+
{ _id: 1, item: "ABC", ratings: [ 2, 9 ] },
121+
{ _id: 2, item: "XYZ", ratings: [ 4, 3 ] }
122+
]
123+
)
124+
116125

117126
Create a :ref:`compound index <index-type-compound>` on the ``item``
118127
field and the ``ratings`` field:
@@ -181,12 +190,17 @@ and ratings to ``[[3.0, 6.0]]`` to use the combined bounds of:
181190
"item" : [ [ "L", "Z" ] ], "ratings" : [ [3.0, 6.0] ]
182191

183192
For another example, consider where the scalar fields belong to a nested document.
184-
For instance, a collection ``survey`` contains the following documents:
193+
For instance, create a ``survey`` collection that contains the following documents:
185194

186195
.. code-block:: javascript
187-
188-
{ _id: 1, item: { name: "ABC", manufactured: 2016 }, ratings: [ 2, 9 ] }
189-
{ _id: 2, item: { name: "XYZ", manufactured: 2013 }, ratings: [ 4, 3 ] }
196+
197+
db.survey.insertMany(
198+
[
199+
{ _id: 1, item: { name: "ABC", manufactured: 2016 }, ratings: [ 2, 9 ] },
200+
{ _id: 2, item: { name: "XYZ", manufactured: 2013 }, ratings: [ 4, 3 ] }
201+
]
202+
)
203+
190204

191205
Create a compound multikey index on the scalar fields ``"item.name"``,
192206
``"item.manufactured"``, and the array field ``ratings`` :

source/reference/command/create.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,18 @@ or if specifying a collation:
530530

531531
db.runCommand( { create: <view>, viewOn: <source>, pipeline: <pipeline>, collation: <collation> } )
532532

533-
For example, given a collection ``survey`` with the following documents:
533+
For example, create a ``survey`` collection with the following documents:
534534

535535
.. code-block:: javascript
536536

537-
{ _id: 1, empNumber: "abc123", feedback: { management: 3, environment: 3 }, department: "A" }
538-
{ _id: 2, empNumber: "xyz987", feedback: { management: 2, environment: 3 }, department: "B" }
539-
{ _id: 3, empNumber: "ijk555", feedback: { management: 3, environment: 4 }, department: "A" }
537+
db.survey.insertMany(
538+
[
539+
{ _id: 1, empNumber: "abc123", feedback: { management: 3, environment: 3 }, department: "A" },
540+
{ _id: 2, empNumber: "xyz987", feedback: { management: 2, environment: 3 }, department: "B" },
541+
{ _id: 3, empNumber: "ijk555", feedback: { management: 3, environment: 4 }, department: "A" }
542+
]
543+
)
544+
540545

541546
The following operation creates a ``managementRatings`` view with the
542547
``_id``, ``feedback.management``, and ``department`` fields:

0 commit comments

Comments
 (0)