Skip to content

Commit eb87f6a

Browse files
i80andkay-kim
authored andcommitted
DOCS-4412: Document sleep()
Signed-off-by: kay <kay.kim@10gen.com>
1 parent fc3cc55 commit eb87f6a

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
arg_name: param
2+
description: |
3+
A duration in milliseconds.
4+
interface: method
5+
name: ms
6+
operation: sleep
7+
optional: false
8+
position: 1
9+
type: integer
10+
...

source/includes/ref-toc-method-native.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ name: ":method:`cd()`"
1010
file: /reference/method/cd
1111
description: "Changes the current working directory to the specified path."
1212
---
13+
name: ":method:`sleep()`"
14+
file: /reference/method/sleep
15+
description: "Suspends the :program:`mongo` shell for a given period of time."
16+
---
1317
name: ":method:`copyDbpath()`"
1418
file: /reference/method/copyDbpath
1519
description: "Copies a local :setting:`~storage.dbPath`. For internal use."

source/reference/method/sleep.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=======
2+
sleep()
3+
=======
4+
5+
.. default-domain:: mongodb
6+
7+
Definition
8+
----------
9+
10+
.. method:: sleep(ms)
11+
12+
.. include:: /includes/apiargs/method-sleep-param.rst
13+
14+
:method:`sleep()` suspends a JavaScript execution context for a specified
15+
number of milliseconds.
16+
17+
Example
18+
-------
19+
20+
Consider a low-priority bulk data import script. To avoid impacting other
21+
processes, you may suspend the shell after inserting each document, distributing
22+
the cost of insertion over a longer priod of time.
23+
24+
The following example :program:`mongo` script will load a JSON file containing
25+
an array of documents, and save one element every 100 milliseconds.
26+
27+
.. code-block:: javascript
28+
29+
JSON.parse(cat('users.json')).forEach(function(user) {
30+
db.users.save(user);
31+
sleep(100);
32+
});

0 commit comments

Comments
 (0)