diff --git a/source/includes/apiargs-method-sleep-param.yaml b/source/includes/apiargs-method-sleep-param.yaml new file mode 100644 index 00000000000..6db481e19b4 --- /dev/null +++ b/source/includes/apiargs-method-sleep-param.yaml @@ -0,0 +1,10 @@ +arg_name: param +description: | + A duration in milliseconds. +interface: method +name: ms +operation: sleep +optional: false +position: 1 +type: integer +... diff --git a/source/includes/ref-toc-method-native.yaml b/source/includes/ref-toc-method-native.yaml index 0b1328c03ad..27b3a1efcae 100644 --- a/source/includes/ref-toc-method-native.yaml +++ b/source/includes/ref-toc-method-native.yaml @@ -10,6 +10,10 @@ name: ":method:`cd()`" file: /reference/method/cd description: "Changes the current working directory to the specified path." --- +name: ":method:`sleep()`" +file: /reference/method/sleep +description: "Suspends the :program:`mongo` shell for a given period of time." +--- name: ":method:`copyDbpath()`" file: /reference/method/copyDbpath description: "Copies a local :setting:`~storage.dbPath`. For internal use." diff --git a/source/reference/method/sleep.txt b/source/reference/method/sleep.txt new file mode 100644 index 00000000000..8086f131e71 --- /dev/null +++ b/source/reference/method/sleep.txt @@ -0,0 +1,32 @@ +======= +sleep() +======= + +.. default-domain:: mongodb + +Definition +---------- + +.. method:: sleep(ms) + + .. include:: /includes/apiargs/method-sleep-param.rst + + :method:`sleep()` suspends a JavaScript execution context for a specified + number of milliseconds. + +Example +------- + +Consider a low-priority bulk data import script. To avoid impacting other +processes, you may suspend the shell after inserting each document, distributing +the cost of insertion over a longer priod of time. + +The following example :program:`mongo` script will load a JSON file containing +an array of documents, and save one element every 100 milliseconds. + +.. code-block:: javascript + + JSON.parse(cat('users.json')).forEach(function(user) { + db.users.save(user); + sleep(100); + });