|
1 | 1 | .. _vsce-databases-collections:
|
2 | 2 |
|
3 |
| -============================================== |
4 |
| -Navigate Databases, Collections, and Documents |
5 |
| -============================================== |
| 3 | +================== |
| 4 | +Navigate Your Data |
| 5 | +================== |
6 | 6 |
|
7 | 7 | .. default-domain:: mongodb
|
8 | 8 |
|
9 | 9 | .. contents:: On this page
|
10 | 10 | :local:
|
11 | 11 | :backlinks: none
|
12 |
| - :depth: 1 |
| 12 | + :depth: 2 |
13 | 13 | :class: singlecol
|
| 14 | + |
| 15 | +Once you connect to your deployment using |vsce|, use the left |
| 16 | +navigation to: |
| 17 | + |
| 18 | +- Explore your databases, collections, read-only views, and documents. |
| 19 | + |
| 20 | +- Create new databases and collections. |
| 21 | + |
| 22 | +- Drop databases and collections. |
| 23 | + |
| 24 | +.. figure:: /images/dbs-colls-docs.png |
| 25 | + :figwidth: 300px |
| 26 | + :alt: Image showing deployment navigation |
| 27 | + |
| 28 | +Databases and Collections |
| 29 | +------------------------- |
| 30 | + |
| 31 | +When you expand an active connection, |vsce| shows the databases in that |
| 32 | +deployment. Click a database to view the collections it contains. |
| 33 | + |
| 34 | +View Collection Documents and Schema |
| 35 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 36 | + |
| 37 | +Click a collection to view its documents and schema. |
| 38 | + |
| 39 | +Documents |
| 40 | +`````````` |
| 41 | + |
| 42 | +When you expand a collection's documents, |vsce| lists the ``_id`` of |
| 43 | +each document in the collection. Click an ``_id`` value to open that |
| 44 | +document in VS Code and view its contents. |
| 45 | + |
| 46 | +.. note:: |
| 47 | + |
| 48 | + You cannot open a single document within a read-only view. |
| 49 | + |
| 50 | +Alternatively, right-click a collection and click |
| 51 | +:guilabel:`View Documents` to view all of the collection's documents |
| 52 | +in an array. |
| 53 | + |
| 54 | +Opening collection documents provides a **read-only** view of your data. |
| 55 | +To modify your data using |vsce|, use a JavaScript Playground. |
| 56 | + |
| 57 | +Schema |
| 58 | +`````` |
| 59 | + |
| 60 | +Your collection's schema defines the fields and data types within the |
| 61 | +collection. Due to MongoDB's flexible schema model, different documents |
| 62 | +in a collection may contain different fields, and data types may vary |
| 63 | +within a field. MongoDB can enforce |
| 64 | +:manual:`schema validation </core/schema-validation/>` to ensure your |
| 65 | +collection documents have the same shape. |
| 66 | + |
| 67 | +When you expand a collection's schema, |vsce| lists the fields which |
| 68 | +appear in that collection's documents. If a field exists in all |
| 69 | +documents and its type is consistent throughout the collection, |vsce| |
| 70 | +displays an icon indicating that field's data type. |
| 71 | + |
| 72 | +Create a New Database |
| 73 | +~~~~~~~~~~~~~~~~~~~~~ |
| 74 | + |
| 75 | +When you create a new database, you must populate it with an |
| 76 | +initial collection. |
| 77 | + |
| 78 | +To create a new database: |
| 79 | + |
| 80 | +1. Hover over the connection for the deployment where you want your |
| 81 | + database to exist. |
| 82 | + |
| 83 | +#. Click the :icon-fa5:`plus` icon that appears. |
| 84 | + |
| 85 | +#. In the prompt, enter a name for your new database. |
| 86 | + |
| 87 | +#. Press the enter key. |
| 88 | + |
| 89 | +#. Enter a name for the first collection in your new database. |
| 90 | + |
| 91 | +#. Press the enter key. |
| 92 | + |
| 93 | +Create a New Collection |
| 94 | +~~~~~~~~~~~~~~~~~~~~~~~ |
| 95 | + |
| 96 | +To create a new collection: |
| 97 | + |
| 98 | +1. Hover over the database where you want your collection to exist. |
| 99 | + |
| 100 | +#. Click the :icon:`plus` icon that appears. |
| 101 | + |
| 102 | +#. In the prompt, enter a name for your new collection. |
| 103 | + |
| 104 | +#. Press the enter key to confirm your new collection. |
| 105 | + |
| 106 | +Drop a Database or Collection |
| 107 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 108 | + |
| 109 | +.. important:: |
| 110 | + |
| 111 | + Dropping data from MongoDB is an irreversible process. Take caution |
| 112 | + to only drop data you are sure you want to delete, and backup your |
| 113 | + data as necessary. |
| 114 | + |
| 115 | + Dropping a database also drops all collections and documents within |
| 116 | + that database. |
| 117 | + |
| 118 | +To drop a database or collection: |
| 119 | + |
| 120 | +1. Right-click the target database or collection. |
| 121 | + |
| 122 | +#. Click :guilabel:`Drop Database` or :guilabel:`Drop Collection`. |
| 123 | + |
| 124 | +#. In the prompt, type the name of the target database or collection. |
| 125 | + |
| 126 | +#. Press the enter key. |
| 127 | + |
| 128 | +Refresh Data |
| 129 | +------------ |
| 130 | + |
| 131 | +You can refresh a deployment, database, or collection at any time to |
| 132 | +re-query your deployment and populate |vsce| with the most up-to-date |
| 133 | +data. |
| 134 | + |
| 135 | +To refresh: |
| 136 | + |
| 137 | +1. Right-click the target deployment, database, or collection. |
| 138 | + |
| 139 | +#. Click :guilabel:`Refresh`. |
0 commit comments