Skip to content

Commit 88bf6eb

Browse files
author
Dave
authored
Docsp 19930 update insert pt3 v5.1 (#88) (#89)
* DOCSP-19930-update-insert-pt3 * Add more files * One more * Staging tweaks * Feedback comments
1 parent 79ca2dd commit 88bf6eb

10 files changed

+37
-121
lines changed

source/includes/fact-bulkwrite-explainable.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33

44
.. end-explainable
55
6-
Use |old-write-method| instead.

source/reference/command/update.txt

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ update
44

55
.. default-domain:: mongodb
66

7-
8-
97
.. contents:: On this page
108
:local:
119
:backlinks: none
@@ -25,11 +23,8 @@ Definition
2523
:binary:`~bin.mongosh` provides the following helper methods:
2624

2725
- :method:`db.collection.updateOne()`
28-
2926
- :method:`db.collection.updateMany()`
3027

31-
- :method:`db.collection.update()`
32-
3328
Syntax
3429
------
3530

@@ -74,65 +69,41 @@ The command takes the following fields:
7469
:widths: 20 20 80
7570

7671
* - Field
77-
7872
- Type
79-
8073
- Description
8174

8275
* - ``update``
83-
8476
- string
85-
8677
- The name of the target collection.
87-
88-
8978

9079
* - ``updates``
91-
9280
- array
93-
9481
- An array of one or more update statements to perform on the named
9582
collection. For details of the update statements, see :ref:`Update
9683
Statements <update-statement-documents>`.
97-
98-
9984

10085
* - ``ordered``
101-
10286
- boolean
103-
10487
- Optional. If ``true``, then when an update statement fails, return without
10588
performing the remaining update statements. If ``false``, then when
10689
an update fails, continue with the remaining update statements, if
10790
any. Defaults to ``true``.
108-
109-
11091

11192
* - ``writeConcern``
112-
11393
- document
114-
11594
- Optional. A document expressing the :doc:`write concern </reference/write-concern>`
11695
of the :dbcommand:`update` command. Omit to use the default write
11796
concern.
11897

11998
.. include:: /includes/extracts/transactions-operations-write-concern.rst
120-
121-
12299

123100
* - ``bypassDocumentValidation``
124-
125101
- boolean
126-
127102
- Optional. Enables :dbcommand:`update` to bypass document validation
128103
during the operation. This lets you update documents that do not
129104
meet the validation requirements.
130-
131-
.. versionadded:: 3.2
132-
133-
134-
* - ``comment``
135105

106+
* - ``comment``
136107
- any
137108

138109
- .. include:: /includes/extracts/comment-content.rst
@@ -141,13 +112,11 @@ The command takes the following fields:
141112

142113

143114
* - :ref:`let <update-let-syntax>`
144-
145115
- document
146-
147116
- .. _update-let-syntax:
148-
117+
149118
Optional.
150-
119+
151120
.. include:: /includes/let-variables-syntax.rst
152121

153122
For a complete MQL example, see :ref:`update-variables-example`.
@@ -167,50 +136,39 @@ Each document contains the following fields:
167136
:widths: 20 20 80
168137

169138
* - Field
170-
171139
- Type
172-
173140
- Description
174141

175142
* - :ref:`q <update-command-q>`
176-
177143
- document
178-
179144
- .. _update-command-q:
180145

181146
The query that matches documents to update. Use the same :ref:`query
182147
selectors <query-selectors>` as used in the :method:`find()
183148
<db.collection.find()>` method.
184149

185150
* - :ref:`u <update-command-u>`
186-
187151
- document or pipeline
188-
189152
- .. _update-command-u:
190153

191154
The modifications to apply.
192-
193155
The value can be either:
194156

195157
- A document that contains :ref:`update operator expressions
196158
<update-operators>`,
197-
198159
- A replacement document with only ``<field1>: <value1>`` pairs, or
199-
200160
- Starting in MongoDB 4.2, an aggregation pipeline.
201161

202162
.. include:: /includes/list-update-agg-stages.rst
203163

204164
For details, see :ref:`update-command-behaviors`.
205165

206166
* - :ref:`c <update-command-c>`
207-
208167
- document
209-
210168
- .. _update-command-c:
211169

212170
Optional.
213-
171+
214172
.. include:: /includes/let-variables-syntax.rst
215173

216174
.. include:: /includes/let-variables-syntax-note.rst
@@ -221,17 +179,13 @@ Each document contains the following fields:
221179
.. versionadded:: 5.0
222180

223181
* - :ref:`upsert <update-command-upsert>`
224-
225182
- boolean
226-
227183
- .. _update-command-upsert:
228184

229185
.. include:: /includes/extracts/update-upsert-behavior-command.rst
230186

231187
* - ``multi``
232-
233188
- boolean
234-
235189
- Optional. If ``true``, updates all documents that meet the query criteria. If
236190
``false``, limit the update to one document that meet the query
237191
criteria. Defaults to ``false``.
@@ -776,11 +730,11 @@ values to calculate a separate field value.
776730

777731
.. code-block:: javascript
778732

779-
db.students.insert([
733+
db.students.insertMany( [
780734
{ "_id" : 1, "tests" : [ 95, 92, 90 ] },
781735
{ "_id" : 2, "tests" : [ 94, 88, 90 ] },
782736
{ "_id" : 3, "tests" : [ 70, 75, 82 ] }
783-
]);
737+
] );
784738

785739
Using an aggregation pipeline, you can update the documents with the
786740
calculated grade average and letter grade.
@@ -924,24 +878,24 @@ documents:
924878

925879
.. code-block:: javascript
926880

927-
db.students.insert([
881+
db.students.insertMany( [
928882
{ "_id" : 1, "grades" : [ 95, 92, 90 ] },
929883
{ "_id" : 2, "grades" : [ 98, 100, 102 ] },
930884
{ "_id" : 3, "grades" : [ 95, 110, 100 ] }
931-
]);
885+
] );
932886

933887
To modify all elements that are greater than or equal to ``100`` in the
934888
``grades`` array, use the filtered positional operator
935889
:update:`$[\<identifier\>]` with the ``arrayFilters`` option:
936890

937891
.. code-block:: javascript
938892

939-
db.runCommand({
893+
db.runCommand( {
940894
update: "students",
941895
updates: [
942896
{ q: { grades: { $gte: 100 } }, u: { $set: { "grades.$[element]" : 100 } }, arrayFilters: [ { "element": { $gte: 100 } } ], multi: true}
943897
]
944-
})
898+
} )
945899

946900
After the operation, the collection contains the following documents:
947901

@@ -959,7 +913,7 @@ Create a collection ``students2`` with the following documents:
959913

960914
.. code-block:: javascript
961915

962-
db.students2.insert([
916+
db.students2.insertMany( [
963917
{
964918
"_id" : 1,
965919
"grades" : [
@@ -976,7 +930,7 @@ Create a collection ``students2`` with the following documents:
976930
{ "grade" : 85, "mean" : 85, "std" : 4 }
977931
]
978932
}
979-
]);
933+
] )
980934

981935
To modify the value of the ``mean`` field for all elements in the
982936
``grades`` array where the grade is greater than or equal to ``85``,

source/reference/config-database.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
41
.. _config-database:
52

63
===============
@@ -75,7 +72,7 @@ exists):
7572

7673
.. code-block:: javascript
7774

78-
db.testConfigServerWriteAvail.insert( { a : 1 } )
75+
db.testConfigServerWriteAvail.insertOne( { a : 1 } )
7976

8077
If the operation succeeds, the config server is available to process
8178
writes.

source/reference/database-references.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
41
.. _database-references:
52

63
===================
@@ -92,13 +89,13 @@ document:
9289

9390
original_id = ObjectId()
9491

95-
db.places.insert({
92+
db.places.insertOne({
9693
"_id": original_id,
9794
"name": "Broadway Center",
9895
"url": "bc.example.net"
9996
})
10097

101-
db.people.insert({
98+
db.people.insertOne({
10299
"name": "Erin",
103100
"places_id": original_id,
104101
"url": "bc.example.net/Erin"

source/reference/insert-methods.txt

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,12 @@ MongoDB provides the following methods for inserting :ref:`documents
1111
:widths: 35 65
1212

1313
* - :method:`db.collection.insertOne()`
14-
15-
- Inserts a single document into a collection.
14+
- Inserts a single :ref:`document <bson-document-format>` into a
15+
collection.
1616

1717
* - :method:`db.collection.insertMany()`
18-
19-
- :method:`db.collection.insertMany()` inserts *multiple*
20-
:ref:`documents <bson-document-format>` into a collection.
21-
22-
* - :method:`db.collection.insert()`
23-
24-
- :method:`db.collection.insert()` inserts a single document or
25-
multiple documents into a collection.
18+
- Inserts multiple :ref:`documents <bson-document-format>` into a
19+
collection.
2620

2721
.. _additional-inserts:
2822

@@ -31,24 +25,16 @@ Additional Methods for Inserts
3125

3226
The following methods can also add new documents to a collection:
3327

34-
- :method:`db.collection.update()` when used with the ``upsert: true``
35-
option.
36-
3728
- :method:`db.collection.updateOne()` when used with the ``upsert:
3829
true`` option.
39-
4030
- :method:`db.collection.updateMany()` when used with the ``upsert:
4131
true`` option.
42-
4332
- :method:`db.collection.findAndModify()` when used with the ``upsert:
4433
true`` option.
45-
4634
- :method:`db.collection.findOneAndUpdate()` when used with the
4735
``upsert: true`` option.
48-
4936
- :method:`db.collection.findOneAndReplace()` when used with the
5037
``upsert: true`` option.
51-
5238
- :method:`db.collection.bulkWrite()`.
5339

5440
See the individual reference pages for the methods for more information

source/reference/method.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,13 @@ Collection
133133

134134
- Hides an index from the query planner.
135135

136-
* - :method:`db.collection.insert()`
137-
138-
- Creates a new document in a collection.
139-
140136
* - :method:`db.collection.insertOne()`
141137

142-
- Inserts a new document in a collection.
138+
- Inserts a new document into a collection.
143139

144140
* - :method:`db.collection.insertMany()`
145141

146-
- Inserts several new document in a collection.
142+
- Inserts several new documents into a collection.
147143

148144
* - :method:`db.collection.isCapped()`
149145

source/reference/method/Bulk.find.hint.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ Description
2323
to support the :method:`Bulk.find()` for:
2424

2525
- :method:`Bulk.find.replaceOne()`
26-
2726
- :method:`Bulk.find.update()`
28-
2927
- :method:`Bulk.find.updateOne()`.
3028

3129
The option can take an index specification document or the index
@@ -43,13 +41,13 @@ Create an example collection ``orders``:
4341

4442
.. code-block:: javascript
4543

46-
db.orders.insert([
44+
db.orders.insertMany( [
4745
{ "_id" : 1, "item" : "abc", "price" : NumberDecimal("12"), "quantity" : 2, "type": "apparel" },
4846
{ "_id" : 2, "item" : "jkl", "price" : NumberDecimal("20"), "quantity" : 1, "type": "electronics" },
4947
{ "_id" : 3, "item" : "abc", "price" : NumberDecimal("10"), "quantity" : 5, "type": "apparel" },
5048
{ "_id" : 4, "item" : "abc", "price" : NumberDecimal("8"), "quantity" : 10, "type": "apparel" },
5149
{ "_id" : 5, "item" : "jkl", "price" : NumberDecimal("15"), "quantity" : 15, "type": "electronics" }
52-
])
50+
] )
5351

5452
Create the following indexes on the example collection:
5553

source/reference/method/PlanCache.list.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ The examples in this section use the following ``orders`` collection:
136136

137137
.. code-block:: javascript
138138

139-
db.orders.insert([
139+
db.orders.insertMany( [
140140
{ "_id" : 1, "item" : "abc", "price" : NumberDecimal("12"), "quantity" : 2, "type": "apparel" },
141141
{ "_id" : 2, "item" : "jkl", "price" : NumberDecimal("20"), "quantity" : 1, "type": "electronics" },
142142
{ "_id" : 3, "item" : "abc", "price" : NumberDecimal("10"), "quantity" : 5, "type": "apparel" },
143143
{ "_id" : 4, "item" : "abc", "price" : NumberDecimal("8"), "quantity" : 10, "type": "apparel" },
144144
{ "_id" : 5, "item" : "jkl", "price" : NumberDecimal("15"), "quantity" : 15, "type": "electronics" }
145-
])
145+
] )
146146

147147
Create the following indexes on the collection:
148148

0 commit comments

Comments
 (0)