|
| 1 | +--- |
| 2 | +title: "Find your Session ID." |
| 3 | +level: 4 |
| 4 | +ref: session-id |
| 5 | +content: | |
| 6 | +
|
| 7 | + .. example:: |
| 8 | +
|
| 9 | + |mdb-shell| displays the session ID each time you open the shell. |
| 10 | +
|
| 11 | + .. code-block:: javascript |
| 12 | + :copyable: false |
| 13 | + :emphasize-lines: 3 |
| 14 | +
|
| 15 | + $ mongosh |
| 16 | +
|
| 17 | + Current sessionID: c2961dbd6b73b052671d9df0 |
| 18 | + Connecting to: mongodb://127.0.0.1:27017 |
| 19 | + Using MongoDB: 4.2.8 |
| 20 | + Using Mongosh Beta: 0.0.6 |
| 21 | +
|
| 22 | +--- |
| 23 | +title: "View the log for the session." |
| 24 | +level: 4 |
| 25 | +ref: view-session-log |
| 26 | +content: | |
| 27 | +
|
| 28 | + |mdb-shell| saves the log for each session to your user's |
| 29 | + ``.mongodb/mongosh`` directory: |
| 30 | +
|
| 31 | + .. tabs:: |
| 32 | +
|
| 33 | + .. tab:: |
| 34 | + :tabid: macOS and Linux |
| 35 | +
|
| 36 | + .. code-block:: sh |
| 37 | +
|
| 38 | + ~/.mongodb/mongosh/<sessionId>_log |
| 39 | +
|
| 40 | + Run the following command to view the log for a session: |
| 41 | +
|
| 42 | + .. code-block:: sh |
| 43 | +
|
| 44 | + cat ~/.mongodb/mongosh/<sessionId>_log |
| 45 | +
|
| 46 | + Run the following command to tail the log for a session: |
| 47 | +
|
| 48 | + .. code-block:: sh |
| 49 | +
|
| 50 | + tail -f ~/.mongodb/mongosh/<sessionId>_log |
| 51 | +
|
| 52 | + .. tip:: |
| 53 | +
|
| 54 | + You can pipe the output to an installed ``ndjson`` pretty |
| 55 | + printer, such as `pino-colada |
| 56 | + <https://www.npmjs.com/package/pino-colada>`__ |
| 57 | + or `pino-pretty <https://www.npmjs.com/package/pino-pretty>`__ |
| 58 | + to improve readability: |
| 59 | +
|
| 60 | + .. code-block:: sh |
| 61 | +
|
| 62 | + tail -f ~/.mongodb/mongosh/<sessionId>_log | pino-colada |
| 63 | +
|
| 64 | + .. tab:: |
| 65 | + :tabid: windows |
| 66 | +
|
| 67 | + .. code-block:: sh |
| 68 | +
|
| 69 | + %UserProfile%/.mongodb/mongosh/<sessionId>_log |
| 70 | +
|
| 71 | + Run the following PowerShell command to view the log for a session: |
| 72 | +
|
| 73 | + .. code-block:: sh |
| 74 | +
|
| 75 | + Get-Content %UserProfile%/.mongodb/mongosh/<sessionId>_log |
| 76 | +
|
| 77 | + Run the following PowerShell command to tail the log for a |
| 78 | + session: |
| 79 | +
|
| 80 | + .. code-block:: sh |
| 81 | +
|
| 82 | + Get-Content %UserProfile%/.mongodb/mongosh/<sessionId>_log -Wait |
| 83 | +
|
| 84 | + .. tip:: |
| 85 | +
|
| 86 | + You can pipe the output to an installed ``ndjson`` pretty |
| 87 | + printer, such as `pino-colada |
| 88 | + <https://www.npmjs.com/package/pino-colada>`__ |
| 89 | + or `pino-pretty <https://www.npmjs.com/package/pino-pretty>`__ |
| 90 | + to improve readability: |
| 91 | +
|
| 92 | + .. code-block:: sh |
| 93 | +
|
| 94 | + Get-Content %UserProfile%/.mongodb/mongosh/<sessionId>_log -Wait | pino-colada |
| 95 | +
|
| 96 | +... |
0 commit comments