@@ -918,7 +918,7 @@ with :method:`~db.collection.update()`.
918
918
919
919
.. code-block:: javascript
920
920
921
- db.books.insertMany([
921
+ db.books.insertMany( [
922
922
{
923
923
_id: 5,
924
924
item: "RQM909",
@@ -933,7 +933,7 @@ with :method:`~db.collection.update()`.
933
933
info: { publisher: "1111", pages: 72 },
934
934
reorder: true
935
935
}
936
- ])
936
+ ] )
937
937
938
938
The following operation specifies both the ``multi`` option and
939
939
the ``upsert`` option. If matching documents exist, the
@@ -1067,10 +1067,10 @@ Create a ``members`` collection with the following documents:
1067
1067
1068
1068
.. code-block:: javascript
1069
1069
1070
- db.members.insertMany([
1070
+ db.members.insertMany( [
1071
1071
{ "_id" : 1, "member" : "abc123", "status" : "A", "points" : 2, "misc1" : "note to self: confirm status", "misc2" : "Need to activate", "lastUpdate" : ISODate("2019-01-01T00:00:00Z") },
1072
1072
{ "_id" : 2, "member" : "xyz123", "status" : "A", "points" : 60, "misc1" : "reminder: ping me at 100pts", "misc2" : "Some random comment", "lastUpdate" : ISODate("2019-01-01T00:00:00Z") }
1073
- ])
1073
+ ] )
1074
1074
1075
1075
Assume that instead of separate ``misc1`` and ``misc2`` fields, you
1076
1076
want to gather these into a new ``comments`` field. The following
@@ -1133,11 +1133,11 @@ Create a ``students3`` collection with the following documents:
1133
1133
1134
1134
.. code-block:: javascript
1135
1135
1136
- db.students3.insert( [
1136
+ db.students3.insertMany( [
1137
1137
{ "_id" : 1, "tests" : [ 95, 92, 90 ], "lastUpdate" : ISODate("2019-01-01T00:00:00Z") },
1138
1138
{ "_id" : 2, "tests" : [ 94, 88, 90 ], "lastUpdate" : ISODate("2019-01-01T00:00:00Z") },
1139
1139
{ "_id" : 3, "tests" : [ 70, 75, 82 ], "lastUpdate" : ISODate("2019-01-01T00:00:00Z") }
1140
- ]);
1140
+ ] )
1141
1141
1142
1142
Using an aggregation pipeline, you can update the documents with the
1143
1143
calculated grade average and letter grade.
@@ -1219,11 +1219,11 @@ collection with the following documents:
1219
1219
1220
1220
.. code-block:: javascript
1221
1221
1222
- db.students.insertMany([
1222
+ db.students.insertMany( [
1223
1223
{ "_id" : 1, "grades" : [ 95, 92, 90 ] },
1224
1224
{ "_id" : 2, "grades" : [ 98, 100, 102 ] },
1225
1225
{ "_id" : 3, "grades" : [ 95, 110, 100 ] }
1226
- ])
1226
+ ] )
1227
1227
1228
1228
To update all elements that are greater than or equal to ``100`` in the
1229
1229
``grades`` array, use the filtered positional operator
@@ -1260,7 +1260,7 @@ collection with the following documents:
1260
1260
1261
1261
.. code-block:: javascript
1262
1262
1263
- db.students2.insertMany([
1263
+ db.students2.insertMany( [
1264
1264
{
1265
1265
"_id" : 1,
1266
1266
"grades" : [
@@ -1277,7 +1277,7 @@ collection with the following documents:
1277
1277
{ "grade" : 85, "mean" : 85, "std" : 4 }
1278
1278
]
1279
1279
}
1280
- ])
1280
+ ] )
1281
1281
1282
1282
To modify the value of the ``mean`` field for all elements in the
1283
1283
``grades`` array where the grade is greater than or equal to ``85``,
@@ -1328,14 +1328,14 @@ collection with the following documents:
1328
1328
1329
1329
.. code-block:: javascript
1330
1330
1331
- db.members.insertMany([
1331
+ db.members.insertMany( [
1332
1332
{ "_id" : 1, "member" : "abc123", "status" : "P", "points" : 0, "misc1" : null, "misc2" : null },
1333
1333
{ "_id" : 2, "member" : "xyz123", "status" : "A", "points" : 60, "misc1" : "reminder: ping me at 100pts", "misc2" : "Some random comment" },
1334
1334
{ "_id" : 3, "member" : "lmn123", "status" : "P", "points" : 0, "misc1" : null, "misc2" : null },
1335
1335
{ "_id" : 4, "member" : "pqr123", "status" : "D", "points" : 20, "misc1" : "Deactivated", "misc2" : null },
1336
1336
{ "_id" : 5, "member" : "ijk123", "status" : "P", "points" : 0, "misc1" : null, "misc2" : null },
1337
1337
{ "_id" : 6, "member" : "cde123", "status" : "A", "points" : 86, "misc1" : "reminder: ping me at 100pts", "misc2" : "Some random comment" }
1338
- ])
1338
+ ] )
1339
1339
1340
1340
Create the following indexes on the collection:
1341
1341
@@ -1430,12 +1430,11 @@ In :binary:`~bin.mongosh`, create a collection named
1430
1430
1431
1431
.. code-block:: javascript
1432
1432
1433
- db.myColl.insertMany(
1434
- [
1433
+ db.myColl.insertMany( [
1435
1434
{ _id: 1, category: "café", status: "A" },
1436
1435
{ _id: 2, category: "cafe", status: "a" },
1437
1436
{ _id: 3, category: "cafE", status: "a" }
1438
- ] )
1437
+ ] )
1439
1438
1440
1439
The following operation includes the :ref:`collation <collation>`
1441
1440
option and sets ``multi`` to ``true`` to update all matching documents:
0 commit comments