|
| 1 | +.. _vs-code-enable-autocomplete: |
| 2 | + |
| 3 | +======================================= |
| 4 | +Enable Autocomplete for String Literals |
| 5 | +======================================= |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 1 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +You can optionally enable autocomplete for string literals |
| 14 | +inside VSCode. Enabling autocomplete for string literals lets you |
| 15 | +automatically populate database and collection names when using |
| 16 | +``use("")`` or ``db.getCollection("")`` syntax within a MongoDB |
| 17 | +playground. |
| 18 | + |
| 19 | +About this Task |
| 20 | +--------------- |
| 21 | + |
| 22 | +- Enabling autocomplete for string literals is a global |
| 23 | + VSCode setting. Changing this setting may affect the behavior and |
| 24 | + performance of other extensions and of VSCode itself. |
| 25 | + |
| 26 | +- If you do not want to enable autocomplete for string literals inside |
| 27 | + VSCode, you can use the keyboard shortcut :kbd:`Ctrl` + :kbd:`Space`. |
| 28 | + This shortcut prompts autocomplete for string literals in your |
| 29 | + MongoDB playground. |
| 30 | + |
| 31 | +Before you Begin |
| 32 | +---------------- |
| 33 | + |
| 34 | +Install the :ref:`MongoDB VSCode extension <vsce-install>`. |
| 35 | + |
| 36 | +Steps |
| 37 | +----- |
| 38 | + |
| 39 | +.. procedure:: |
| 40 | + :style: connected |
| 41 | + |
| 42 | + .. step:: Open Settings.json |
| 43 | + |
| 44 | + In VSCode, open the command palette: |
| 45 | + |
| 46 | + .. list-table:: |
| 47 | + :header-rows: 1 |
| 48 | + :widths: 30 70 |
| 49 | + |
| 50 | + * - Operating System |
| 51 | + - Keyboard Command |
| 52 | + |
| 53 | + * - Windows |
| 54 | + - :kbd:`CTRL` + :kbd:`SHIFT` + :kbd:`P` |
| 55 | + |
| 56 | + * - MacOS |
| 57 | + - :kbd:`CMD` + :kbd:`SHIFT` + :kbd:`P` |
| 58 | + |
| 59 | + Enter :guilabel:`Open User Settings (JSON)` and select the option |
| 60 | + from the autocompleted list: |
| 61 | + |
| 62 | + .. figure:: /images/vsce-command-palette-json-settings.png |
| 63 | + :figwidth: 700px |
| 64 | + :alt: Image of a stream connection |
| 65 | + |
| 66 | + .. step:: Add the autocomplete snippet to the Settings.json file |
| 67 | + |
| 68 | + Copy the following code snippet: |
| 69 | + |
| 70 | + .. code-block:: |
| 71 | + |
| 72 | + "editor.quickSuggestions": { |
| 73 | + "other": true, |
| 74 | + "comments": false, |
| 75 | + "strings": true |
| 76 | + } |
| 77 | + |
| 78 | + Paste the code into the ``Settings.json`` file: |
| 79 | + |
| 80 | + .. figure:: /images/vsce-add-snippet-json-settings.png |
| 81 | + :figwidth: 700px |
| 82 | + :alt: Image of a stream connection |
| 83 | + |
| 84 | + .. step:: Test the autocompletion feature |
| 85 | + |
| 86 | + In a new playground file connected to your deployment, |
| 87 | + type the first character of a collection name between |
| 88 | + ``db.getCollection("")`` and click the full name to populate |
| 89 | + the collection name: |
| 90 | + |
| 91 | + .. figure:: /images/vsce-get-collection-auto-complete.png |
| 92 | + :figwidth: 700px |
| 93 | + :alt: Get collection autocomplete |
| 94 | + |
| 95 | + You can also autocomplete database names by typing the first |
| 96 | + character of a database name in-between the ``use("")`` statement. |
| 97 | + |
| 98 | +Learn More |
| 99 | +---------- |
| 100 | + |
| 101 | +- :ref:`vsce-playground-databases` |
| 102 | +- :ref:`vsce-aggregation` |
0 commit comments