-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathmethods.txt
1539 lines (912 loc) · 39.5 KB
/
methods.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.. _mdb-shell-methods:
=======
Methods
=======
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
The following document lists the available methods in the |mdb-shell|.
Click a method to see its documentation in the
:manual:`MongoDB Manual </>`, including syntax and examples.
.. include:: /includes/admonitions/connection-resets.rst
Administration Methods
----------------------
.. list-table::
:widths: 30 70
:header-rows: 1
* - Method
- Description
* - :method:`db.adminCommand()`
- Runs a command against the ``admin`` database.
* - :method:`db.currentOp()`
- Reports the current in-progress operations.
* - :method:`db.killOp()`
- Terminates a specified operation.
* - :method:`db.shutdownServer()`
- Shuts down the current :binary:`~mongod` or :binary:`~mongos`
process cleanly and safely.
* - :method:`db.fsyncLock()`
- Flushes writes to disk and locks the database to prevent write
operations and assist backup operations.
* - :method:`db.fsyncUnlock()`
- Allows writes to continue on a database locked with
:method:`db.fsyncLock()`.
.. _mongosh-methods-atlas-search:
Atlas Search Index Methods
--------------------------
:atlas:`Atlas Search indexes
</atlas-search/atlas-search-overview/#fts-indexes>` let you query data
in :atlas:`Atlas Search </atlas-search>`. Atlas Search indexes enable
performant text search queries by mapping search terms to the documents
that contain those terms.
Use the following methods to manage Atlas Search indexes.
.. important::
The following methods can only be run on deployments hosted on
:atlas:`MongoDB Atlas </>`.
.. list-table::
:widths: 30 70
:header-rows: 1
* - Name
- Description
* - :upcoming:`db.collection.createSearchIndex()
</reference/method/db.collection.createSearchIndex>`
- Creates one or more Atlas Search indexes on a specified
collection.
* - :upcoming:`db.collection.dropSearchIndex()
</reference/method/db.collection.dropSearchIndex>`
- Deletes an existing Atlas Search index.
* - :upcoming:`db.collection.getSearchIndexes()
</reference/method/db.collection.getSearchIndexes>`
- Returns information about existing Atlas Search indexes on a specified
collection.
* - :upcoming:`db.collection.updateSearchIndex()
</reference/method/db.collection.updateSearchIndex>`
- Updates an existing Atlas Search index.
Bulk Operation Methods
----------------------
.. list-table::
:widths: 30 70
:header-rows: 1
* - Method
- Description
* - :method:`db.collection.initializeOrderedBulkOp()`
- Initializes and returns a new :method:`Bulk()` operations builder
for a collection. The builder constructs an ordered list of write
operations that MongoDB executes in bulk.
* - :method:`db.collection.initializeUnorderedBulkOp()`
- Initializes and returns a new :method:`Bulk()` operations builder
for a collection. The builder constructs an unordered list of write
operations that MongoDB executes in bulk.
* - :method:`Bulk()`
- Creates a bulk operations builder used to construct a list of write
operations to perform in bulk for a single collection. To instantiate
the builder, use either the :method:`db.collection.initializeOrderedBulkOp()`
or the :method:`db.collection.initializeUnorderedBulkOp()` method.
* - :method:`Bulk.execute()`
- Executes the list of operations built by the :method:`Bulk()`
operations builder.
* - :method:`Bulk.find()`
- Specifies a query condition for an update or a remove operation.
* - :method:`Bulk.find.hint()`
- Sets the **hint** option that specifies the index to support the
bulk operation.
* - :method:`Bulk.find.remove()`
- Adds a remove operation to a bulk operations list.
* - :method:`Bulk.find.removeOne()`
- Adds a single document remove operation to a bulk operations list.
* - :method:`Bulk.find.replaceOne()`
- Adds a single document replacement operation to a bulk operations
list.
* - :method:`Bulk.find.updateOne()`
- Adds a single document update operation to a bulk operations list.
* - :method:`Bulk.find.update()`
- Adds a **multi** update operation to a bulk operations list. The
method updates specific fields in existing documents.
* - :method:`Bulk.find.upsert()`
- Sets the :manual:`upsert </reference/glossary/#term-upsert>` option
to ``true`` for an update or a replacement operation.
* - :method:`Bulk.getOperations()`
- Returns an array of write operations executed through
:method:`Bulk.execute()`.
* - :method:`Bulk.insert()`
- Adds an insert operation to a bulk operations list.
* - :method:`Bulk.toJSON()`
- Returns a JSON document that contains the number of operations and
batches in the :method:`Bulk()` object.
* - :method:`Bulk.toString()`
- Returns as a string a JSON document that contains the number of
operations and batches in the :method:`Bulk()` object.
.. _mongosh-collection-methods:
Collection Methods
------------------
.. list-table::
:widths: 30 70
:header-rows: 1
* - Method
- Description
* - :method:`db.collection.aggregate()`
- Provides access to the
:manual:`aggregation pipeline </core/aggregation-pipeline>`.
* - :method:`db.collection.bulkWrite()`
- Provides bulk write operation functionality.
.. convertToCapped
* - :method:`db.collection.count()`
- Deprecated in :binary:`~bin.mongosh` 1.0.6. Use
:method:`db.collection.countDocuments()` or
:method:`db.collection.estimatedDocumentCount()` instead.
* - :method:`db.collection.countDocuments()`
- Returns a count of the number of documents in a collection or a
view. Wraps the :pipeline:`$group` aggregation stage with a
:group:`$sum` expression.
* - :method:`db.collection.estimatedDocumentCount()`
- Returns an approximate count of the documents in a collection or
a view.
* - :method:`db.collection.createIndex()`
- Builds an index on a collection.
* - :method:`db.collection.createIndexes()`
- Builds one or more indexes on a collection.
* - :method:`db.collection.dataSize()`
- Returns the size of the collection. Wraps the
:data:`~collStats.size` field in the output of the
:dbcommand:`collStats`.
* - :method:`db.collection.deleteOne()`
- Deletes a single document in a collection.
* - :method:`db.collection.deleteMany()`
- Deletes multiple documents in a collection.
* - :method:`db.collection.distinct()`
- Returns an array of documents that have distinct values for the
specified field.
* - :method:`db.collection.drop()`
- Removes the specified collection from the database.
* - :method:`db.collection.dropIndex()`
- Removes a specified index on a collection.
* - :method:`db.collection.dropIndexes()`
- Removes all indexes on a collection.
* - :method:`db.collection.ensureIndex()`
- Deprecated. Use :method:`db.collection.createIndex()`.
.. exists
* - :method:`db.collection.explain()`
- Returns information on the query execution of various methods.
* - :method:`db.collection.find()`
- Performs a query on a collection or a view and returns a cursor
object.
* - :method:`db.collection.findAndModify()`
- Atomically modifies and returns a single document.
* - :method:`db.collection.findOne()`
- Performs a query and returns a single document.
* - :method:`db.collection.findOneAndDelete()`
- Finds a single document and deletes it.
* - :method:`db.collection.findOneAndReplace()`
- Finds a single document and replaces it.
* - :method:`db.collection.findOneAndUpdate()`
- Finds a single document and updates it.
* - :method:`db.collection.getIndexes()`
- Returns an array of documents that describe the existing indexes
on a collection.
.. getIndexKeys
.. getIndexSpecs
* - :method:`db.collection.getShardDistribution()`
- Prints the data distribution statistics for a sharded collection.
* - :method:`db.collection.getShardVersion()`
- Returns information regarding the state of data in a sharded
cluster.
* - :method:`db.collection.insertOne()`
- Inserts a new document in a collection.
* - :method:`db.collection.insertMany()`
- Inserts several new document in a collection.
* - :method:`db.collection.isCapped()`
- Reports if a collection is a :term:`capped collection`.
* - :method:`db.collection.mapReduce()`
- Runs :term:`map-reduce` aggregation operations on a collection.
* - :method:`db.collection.reIndex()`
- Rebuilds all existing indexes on a collection.
* - :method:`db.collection.renameCollection()`
- Changes the name of a collection.
* - :method:`db.collection.replaceOne()`
- Replaces a single document in a collection.
* - :method:`db.collection.stats()`
- Reports on the state of a collection. Provides a wrapper around
the :dbcommand:`collStats`.
* - :method:`db.collection.storageSize()`
- Reports the total size used by the collection in bytes. Provides
a wrapper around the :data:`~collStats.storageSize` field of the
:dbcommand:`collStats` output.
* - :method:`db.collection.totalIndexSize()`
- Reports the total size used by the indexes on a collection.
Provides a wrapper around the :data:`~collStats.totalIndexSize`
field of the :dbcommand:`collStats` output.
* - :method:`db.collection.totalSize()`
- Reports the total size of a collection, including the size of
all documents and all indexes on a collection.
* - :method:`db.collection.updateOne()`
- Modifies a single document in a collection.
* - :method:`db.collection.updateMany()`
- Modifies multiple documents in a collection.
* - :method:`db.collection.validate()`
- Validates a collection.
* - :method:`db.collection.watch()`
- Opens a :manual:`change stream cursor </changeStreams>` on the
collection.
Connection Methods
------------------
.. list-table::
:widths: 30 70
:header-rows: 1
* - Method
- Description
* - :method:`Mongo()`
- JavaScript constructor to instantiate a database connection from
the ``mongo`` shell or from a JavaScript file.
The :method:`Mongo()` method has the following parameters:
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Parameter
- Type
- Description
* - ``host``
- string
- *Optional*
The connection string for the target database
connection.
If omitted, :method:`Mongo` instantiates a connection to the
localhost interface on the default port ``27017``.
* - ``autoEncryptionOpts``
- Document
- *Optional*
.. versionadded:: 4.2
Configuration parameters for enabling
:manual:`Client-Side Field Level Encryption
</core/security-client-side-encryption>`.
``autoEncryptionOpts`` overrides the
existing client-side field level encryption configuration of
the database connection. If omitted, :method:`Mongo()`
inherits the client-side field level encryption configuration
of the current database connection.
For documentation of usage and syntax, see
:ref:`autoEncryptionOpts`.
* - :method:`Mongo.getDB()`
- Returns a database object.
* - :method:`Mongo.setReadPref()`
- Sets the :term:`read preference` for the MongoDB connection.
* - :method:`Mongo.watch()`
- Opens a :manual:`change stream cursor </changeStreams>` for a replica
set or a sharded cluster to report on all its non-system collections
across its databases, with the exception of the ``admin``, ``local``,
and ``config`` databases.
.. _mongosh-cursor-methods:
Cursor Methods
--------------
.. list-table::
:widths: 30 70
:header-rows: 1
* - Method
- Description
* - :method:`cursor.addOption()`
- Adds special wire protocol flags that modify the behavior of the
query.
* - :method:`cursor.allowPartialResults()`
- Allows :method:`db.collection.find()` operations against a
sharded collection to return partial results, rather than an
error, if one or more queried shards are unavailable.
.. arrayAccess
* - :method:`cursor.batchSize()`
- Specifies the maximum number of documents MongoDB will return to the client
within each batch returned in a query result. By default, the initial batch
size is ``101`` documents and subsequent batches have a maximum
size of 16 mebibytes (MiB). This option can enforce a smaller
limit than 16 MiB, but not a larger one. If you set ``batchSize``
to a limit that results in batches larger than 16 MiB, this option has no effect.
A batchSize of 0 means that the cursor will be established, but no documents
will be returned in the first batch.
The following example query returns results in batches of
100:
.. code-block:: sh
db.myCollection.find().batchSize(100)
* - :method:`cursor.close()`
- Close a cursor and free associated server resources.
* - :method:`cursor.collation()`
- Specifies the collation for the cursor returned by the
:method:`db.collection.find()`.
* - :method:`cursor.comment()`
- Attaches a comment to the query to allow for traceability in the
logs and the system.profile collection.
* - :method:`cursor.count()`
- Modifies the cursor to return the number of documents in the
result set rather than the documents themselves.
* - :method:`cursor.explain()`
- Reports on the query execution plan for a cursor.
* - :method:`cursor.forEach()`
- Applies a JavaScript function for every document in a cursor.
* - :method:`cursor.hasNext()`
- Returns ``true`` if the cursor has documents and can be iterated.
* - :method:`cursor.hint()`
- Forces MongoDB to use a specific index for a query.
* - :method:`cursor.isClosed()`
- Returns ``true`` if the cursor is closed.
* - :method:`cursor.isExhausted()`
- Returns ``true`` if the cursor is closed *and* there are no
objects remaining in the batch.
* - :method:`cursor.itcount()`
- Computes the total number of documents in the cursor client-side
by fetching and iterating the result set.
* - :method:`cursor.limit()`
- Constrains the size of a cursor's result set.
* - :method:`cursor.map()`
- Applies a function to each document in a cursor and collects the
return values in an array.
* - :method:`cursor.max()`
- Specifies an exclusive upper index bound for a cursor. For use
with :method:`cursor.hint()`
* - :method:`cursor.maxTimeMS()`
- Specifies a cumulative time limit in milliseconds for processing
operations on a cursor.
* - :method:`cursor.min()`
- Specifies an inclusive lower index bound for a cursor. For use
with :method:`cursor.hint()`
* - :method:`cursor.next()`
- Returns the next document in a cursor.
* - :method:`cursor.noCursorTimeout()`
- Instructs the server to avoid closing a cursor automatically
after a period of inactivity.
.. oplogReplay
.. projection
* - :method:`cursor.objsLeftInBatch()`
- Returns the number of documents left in the current cursor batch.
* - :method:`cursor.readConcern()`
- Specifies a :term:`read concern` for a
:method:`db.collection.find()` operation.
* - :method:`cursor.readPref()`
- Specifies a :term:`read preference` to a cursor to control how
the client directs queries to a :term:`replica set`.
* - :method:`cursor.returnKey()`
- Modifies the cursor to return index keys rather than the
documents.
* - :method:`cursor.showRecordId()`
- Adds an internal storage engine ID field to each document
returned by the cursor.
* - :method:`cursor.size()`
- Returns a count of the documents in the cursor after applying
:method:`~cursor.skip()` and :method:`~cursor.limit()` methods.
* - :method:`cursor.skip()`
- Returns a cursor that begins returning results only after
passing or skipping a number of documents.
* - :method:`cursor.sort()`
- Returns results ordered according to a sort specification.
* - :method:`cursor.tailable()`
- Marks the cursor as tailable. Only valid for cursors over capped
collections.
* - :method:`cursor.toArray()`
- Returns an array that contains all documents returned by the
cursor.
.. _mongosh-database-methods:
Database Methods
----------------
.. list-table::
:widths: 30 70
:header-rows: 1
* - Method
- Description
* - :method:`db.aggregate()`
- Runs admin/diagnostic pipeline which does not require an
underlying collection.
* - :method:`db.createCollection()`
- Creates a new collection or view.
* - :method:`db.createView()`
- Creates a view as the result of applying the specified
aggregation pipeline to the source collection or view.
* - :method:`db.commandHelp()`
- Displays help text for the specified database command.
* - :method:`db.dropDatabase()`
- Removes the current database.
* - :method:`db.getCollection()`
- Returns a collection or view object. Used to access collections
with names that are not valid in the :binary:`~bin.mongo` shell.
* - :method:`db.getCollectionInfos()`
- Returns collection information for all collections and views in
the current database.
* - :method:`db.getCollectionNames()`
- Lists all collections and views in the current database.
* - :method:`db.getMongo()`
- Returns the current database connection.
* - :method:`db.getLogComponents()`
- Returns the current log verbosity settings.
* - :method:`db.getName()`
- Returns the name of the current database.
* - :method:`db.getProfilingStatus()`
- Returns the current :manual:`profile level
</reference/command/profile/#dbcmd.profile>`, :manual:`slowOpThresholdMs
</reference/configuration-options/#operationProfiling.slowOpThresholdMs>`
setting, and :manual:`slowOpSampleRate
</reference/configuration-options/#operationProfiling.slowOpSampleRate>`
setting.
* - :method:`db.getSiblingDB()`
- Provides access to the specified database.
* - :method:`db.listCommands()`
- Provides a list of all database commands.
* - :method:`db.logout()`
- Ends an authenticated session.
* - :method:`db.printShardingStatus()`
- Prints a formatted report of the sharding configuration and the
information regarding existing chunks in a sharded cluster.
* - :method:`db.runCommand()`
- Runs a :manual:`database command </reference/command>`.
* - :method:`db.setLogLevel()`
- Sets a single verbosity level for :manual:`log messages
</reference/log-messages/>`.
* - :method:`db.setProfilingLevel()`
- Configures the database :manual:`profiler level
</reference/method/db.setProfilingLevel/#set-profiling-level-level>`,
:manual:`slowms
</reference/method/db.setProfilingLevel/#set-profiling-level-options-slowms>`,
and :manual:`sampleRate
</reference/method/db.setProfilingLevel/#set-profiling-level-options-samplerate>`.
* - :method:`db.watch()`
- Opens a :manual:`change stream cursor </change-streams>` for a
database to report on all its non-system collections.
.. _fle-methods-mongosh:
In-Use Encryption Methods
-------------------------
.. note:: Limitations
- Automatic encryption is only available when ``mongosh`` is connected
to an Atlas cluster or a MongoDB Enterprise Server. For details,
see :manual:`Automatic Client-Side Field Level Encryption
</core/security-automatic-client-side-encryption/>`. The methods
listed in this section are used for *manual* encryption, and are
supported on non-enterprise servers.
- Automatic encryption is not available with the Homebrew installation
of ``mongosh``.
- Field level encryption is only available in the ``mongosh`` binary,
and not available in the :compass:`embedded Compass shell
</embedded-shell>`.
.. list-table::
:widths: 40 60
:header-rows: 1
* - Method
- Description
* - :upcoming:`ClientEncryption.createEncryptedCollection()
</reference/method/ClientEncryption.createEncryptedCollection>`
- Creates a collection with encrypted fields.
* - :method:`ClientEncryption.decrypt()`
- Decrypts the specified ``encryptedValue`` if the current database
connection was configured with access to the Key Management Service
(KMS) and key vault used to encrypt ``encryptedValue``.
* - :method:`ClientEncryption.encrypt()`
- Encrypts the specified value using the specified ``encryptionKeyId``
and ``encryptionAlgorithm``.
* - :method:`getClientEncryption()`
- Returns the ``ClientEncryption`` object for the current database
collection.
* - :method:`getKeyVault()`
- Returns the ``KeyVault`` object for the current database connection.
* - :method:`KeyVault.addKeyAlternateName()`
- Adds the ``keyAltName`` to the ``keyAltNames`` array of the data
encryption key with the specified UUID.
* - :method:`KeyVault.createKey()`
- Adds a data encryption key to the key vault associated to the
database connection.
* - :method:`KeyVault.deleteKey()`
- Deletes a data encryption key with the specified UUID from the key
vault associated to the database connection.
* - :method:`KeyVault.getKey()`
- Gets a data encryption key with the specified UUID. The data
encryption key must exist in the key vault associated to the
database connection.
* - :method:`KeyVault.getKeyByAltName()`
- Gets all data encryption keys with the specified ``keyAltName``.
* - :method:`KeyVault.getKeys()`
- Returns all data encryption keys stored in the key vault associated
to the database connection.
* - :method:`KeyVault.removeKeyAlternateName()`
- Removes the specified ``keyAltName`` from the data encryption key
with the specified UUID. The data encryption key must exist in the
key vault associated to the database connection.
Native Methods
--------------
.. list-table::
:widths: 30 70
:header-rows: 1
* - Method
- Description
* - .. _mongosh-native-method-buildInfo():
``buildInfo()``
- .. include:: /includes/examples/ex-build-info-command.rst
* - .. _mongosh-native-method-cd:
``cd()``
- Changes the current working directory to the specified path.
* - .. _mongosh-native-method-isInteractive:
``isInteractive()``
- Returns a boolean indicating whether mongosh is running in
interactive or script mode.
* - .. _mongosh-native-method-load:
``load()``
- Loads and runs a JavaScript file in the shell.
In ``mongosh``, scripts loaded with the ``load()`` method support
the ``__filename`` and ``__dirname`` Node.js variables. These
variables return the file name and directory of the loaded
script, respectively. The returned values are always absolute
paths.
.. include:: /includes/legacy/legacy-load-method.rst
* - .. _mongosh-native-method-print:
``print()``
- Print the specified text or variable. ``print()`` and ``printjson()``
are aliases for ``console.log()``.
.. code-block:: code
> print("hello world")
hello world
> x = "example text"
> print(x)
example text
* - .. _mongosh-native-method-pwd:
``pwd()``
- Returns the current working directory of the active shell session.
* - .. _mongosh-native-method-quit:
``quit()``
- Exits the current shell session.
* - .. _mongosh-native-method-sleep:
``sleep()``
- Suspends the |mongo| shell for a given period of time.
* - .. _mongosh-native-method-version:
``version()``
- Returns the current version of the ``mongosh`` instance.
Query Plan Cache Methods
------------------------
.. list-table::
:widths: 30 70
:header-rows: 1
* - Method
- Description
* - :method:`db.collection.getPlanCache()`
- Returns an interface to access the query plan cache object and
associated ``PlanCache`` methods for a collection.
* - :method:`PlanCache.clear()`
- Removes all cached query plans for a collection.
* - :method:`PlanCache.clearPlansByQuery()`
- Clears the cached query plans for the specified
:term:`query shape`.
* - :method:`PlanCache.help()`
- Lists the methods available to view and modify a collection’s
query plan cache.
* - :method:`PlanCache.list()`
- Returns an array of
:manual:`plan cache entries </core/query-plans/>`
for a collection.
.. _mongosh-replication-methods:
Replication Methods
-------------------
.. list-table::
:widths: 30 70
:header-rows: 1
* - Method
- Description
* - :method:`rs.add()`
- Adds a member to the replica set. You must connect to the
primary of the replica set to run this method.
* - :method:`rs.addArb()`
- Adds an arbiter to an existing replica set.
* - :method:`rs.config()`
- Returns a document that contains the current replica set configuration.
* - :method:`rs.freeze()`
- Makes the replica set member that ``mongosh`` is connected to