@@ -18,7 +18,7 @@ This tutorial covers both the basic CRUD methods and the specialized ``findAndMo
18
18
as well as the new Bulk API methods for efficient bulk write operations.
19
19
20
20
<div class =" pull-right " >
21
- <input type =" checkbox " checked =" " class =" distroPicker " data-toggle =" toggle " data-on =" ES2015 " data-off =" ES2017 " data-offstyle =" success " >
21
+ <input type =" checkbox " checked =" " class =" distroPicker " data-toggle =" toggle " data-on =" ES2017 " data-off =" ES2015 " data-offstyle =" success " >
22
22
</div >
23
23
24
24
@@ -33,7 +33,7 @@ The ``insertOne`` and ``insertMany`` methods exist on the ``Collection`` class a
33
33
34
34
35
35
36
- <section class =" javascript5 " ><pre ><code class =" hljs " >
36
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
37
37
{{% myproject-connect %}}
38
38
39
39
// Insert a single document
@@ -52,7 +52,7 @@ The ``insertOne`` and ``insertMany`` methods exist on the ``Collection`` class a
52
52
});
53
53
54
54
</code ></pre ></section >
55
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
55
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
56
56
{{% js6-connect %}}
57
57
58
58
// Insert a single document
@@ -90,7 +90,7 @@ The ``insertOne`` and ``insertMany`` methods also accept a second argument which
90
90
The following example shows how to serialize a passed-in function when writing to a
91
91
[ replica set] ( https://docs.mongodb.org/manual/core/replica-set-members/ ) .
92
92
93
- <section class =" javascript5 " ><pre ><code class =" hljs " >
93
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
94
94
{{% myproject-connect %}}
95
95
96
96
// Insert a single document
@@ -108,7 +108,7 @@ The following example shows how to serialize a passed-in function when writing t
108
108
});
109
109
});
110
110
</code ></pre ></section >
111
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
111
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
112
112
{{% js6-connect %}}
113
113
114
114
// Insert a single document
@@ -140,7 +140,7 @@ when inserting documents with the ``insertMany`` method.
140
140
The Decimal128 data type requires MongoDB server version 3.4 or higher.
141
141
{{% /note %}}
142
142
143
- <section class =" javascript5 " ><pre ><code class =" hljs " >
143
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
144
144
const Long = require('mongodb').Long;
145
145
const Decimal = require('mongodb').Decimal128;
146
146
@@ -158,7 +158,7 @@ const Decimal = require('mongodb').Decimal128;
158
158
});
159
159
160
160
</code ></pre ></section >
161
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
161
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
162
162
const Long = require('mongodb').Long;
163
163
const Decimal = require('mongodb').Decimal128;
164
164
@@ -191,7 +191,7 @@ The above operation inserts the following documents into the
191
191
192
192
The `` updateOne `` and `` updateMany `` methods exist on the `` Collection `` class and are used to update and upsert documents.
193
193
194
- <section class =" javascript5 " ><pre ><code class =" hljs " >
194
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
195
195
{{% myproject-connect %}}
196
196
197
197
const col = db.collection('updates');
@@ -226,7 +226,7 @@ The ``updateOne`` and ``updateMany`` methods exist on the ``Collection`` class a
226
226
});
227
227
});
228
228
</code ></pre ></section >
229
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
229
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
230
230
{{% js6-connect %}}
231
231
232
232
// Get the updates collection
@@ -276,7 +276,7 @@ Just as for ``insert``, the ``update`` method allows you to specify a per operat
276
276
277
277
The `` deleteOne `` and `` deleteMany `` methods exist on the `` Collection `` class and are used to remove documents from MongoDB.
278
278
279
- <section class =" javascript5 " ><pre ><code class =" hljs " >
279
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
280
280
{{% myproject-connect %}}
281
281
282
282
const col = db.collection('removes');
@@ -300,7 +300,7 @@ The ``deleteOne`` and ``deleteMany`` methods exist on the ``Collection`` class a
300
300
});
301
301
});
302
302
</code ></pre ></section >
303
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
303
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
304
304
{{% js6-connect %}}
305
305
306
306
// Get the removes collection
@@ -343,7 +343,7 @@ allow the user to update or upsert a document and have the modified or existing
343
343
methods, the operation takes a write lock for the duration of the operation in order to ensure the modification is
344
344
[ atomic] ( https://docs.mongodb.org/manual/core/write-operations-atomicity/ ) .
345
345
346
- <section class =" javascript5 " ><pre ><code class =" hljs " >
346
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
347
347
{{% myproject-connect %}}
348
348
349
349
const col = db.collection('findAndModify');
@@ -371,7 +371,7 @@ methods, the operation takes a write lock for the duration of the operation in o
371
371
});
372
372
});
373
373
</code ></pre ></section >
374
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
374
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
375
375
{{% js6-connect %}}
376
376
377
377
// Get the findAndModify collection
@@ -414,7 +414,7 @@ The ``findOneAndUpdate`` method also accepts a third argument which can be an op
414
414
415
415
The `` findOneAndDelete `` function is designed to help remove a document.
416
416
417
- <section class =" javascript5 " ><pre ><code class =" hljs " >
417
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
418
418
{{% myproject-connect %}}
419
419
420
420
const col = db.collection('findAndModify');
@@ -435,7 +435,7 @@ The ``findOneAndDelete`` function is designed to help remove a document.
435
435
});
436
436
});
437
437
</code ></pre ></section >
438
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
438
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
439
439
{{% js6-connect %}}
440
440
441
441
// Get the findAndModify collection
@@ -471,7 +471,7 @@ Like ``findOneAndUpdate``, it allows an object of options to be passed in which
471
471
472
472
The `` bulkWrite `` function allows a simple set of bulk operations to run in a non-fluent way, in comparison to the bulk API discussed next.
473
473
474
- <section class =" javascript5 " ><pre ><code class =" hljs " >
474
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
475
475
{{% myproject-connect %}}
476
476
477
477
// Get the collection
@@ -498,7 +498,7 @@ The ``bulkWrite`` function allows a simple set of bulk operations to run in a no
498
498
});
499
499
});
500
500
</code ></pre ></section >
501
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
501
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
502
502
{{% js6-connect %}}
503
503
504
504
// Get the collection
@@ -540,7 +540,7 @@ The ``bulkWrite`` function takes an array of operations which can be objects of
540
540
541
541
Bulk write operations make it easy to write groups of operations together to MongoDB. There are some caveats and to get the best performance you need to be running against MongoDB version 2.6 or higher, which supports the new write commands. Bulk operations are split into * ordered* and * unordered* bulk operations. An * ordered* bulk operation guarantees the order of execution of writes while the * unordered* bulk operation makes no assumptions about the order of execution. In the Node.js driver the * unordered* bulk operations will group operations according to type and write them in parallel.
542
542
543
- <section class =" javascript5 " ><pre ><code class =" hljs " >
543
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
544
544
{{% myproject-connect %}}
545
545
546
546
const col = db.collection('bulkops');
@@ -566,7 +566,7 @@ Bulk write operations make it easy to write groups of operations together to Mon
566
566
});
567
567
});
568
568
</code ></pre ></section >
569
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
569
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
570
570
{{% js6-connect %}}
571
571
572
572
// Get the collection
@@ -641,7 +641,7 @@ The main method for querying the database is the ``find`` method.
641
641
642
642
The following example materializes all the documents from a query using the `` toArray `` method, but limits the number of returned results to two documents.
643
643
644
- <section class =" javascript5 " ><pre ><code class =" hljs " >
644
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
645
645
{{% myproject-connect %}}
646
646
647
647
const col = db.collection('find');
@@ -659,7 +659,7 @@ The following example materializes all the documents from a query using the ``to
659
659
});
660
660
});
661
661
</code ></pre ></section >
662
- <section class =" javascript6 hidden " ><pre ><code class =" hljs " >
662
+ <section class =" javascript6 " ><pre ><code class =" hljs " >
663
663
{{% js6-connect %}}
664
664
665
665
// Get the collection
@@ -715,7 +715,7 @@ More information can be found in the [Cursor API documentation](/node-mongodb-na
715
715
716
716
The following example uses the `` next `` method.
717
717
718
- <section class =" javascript5 " ><pre ><code class =" hljs " >
718
+ <section class =" javascript5 hidden " ><pre ><code class =" hljs " >
719
719
{{% myproject-connect %}}
720
720
721
721
const col = db.collection('find');
@@ -733,7 +733,7 @@ The following example uses the ``next`` method.
733
733
});
734
734
});
735
735
</code ></pre ></section >
736
- <section class =" javascript6 hidden " >
736
+ <section class =" javascript6 " >
737
737
In ECMAScript 6, The new ` generator ` functions allow for what is arguably a
738
738
much cleaner and easier way to read iteration code.
739
739
0 commit comments