-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathplayground-databases.txt
117 lines (79 loc) · 3.22 KB
/
playground-databases.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
.. _vsce-playground-databases:
================================
Create Databases and Collections
================================
.. meta::
:description: Create databases and collections using MongoDB Playground in VS Code by following a template and running the playground.
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
You can create
:manual:`databases and collections </core/databases-and-collections/>`
using a MongoDB Playground.
Prerequisites
-------------
If you have not done so already, you must complete the following
prerequisites before you can create a database or collection with a
MongoDB Playground:
- :ref:`Create a connection to a MongoDB deployment
<vsce-connect-task>`.
- :ref:`Activate the connection to the MongoDB deployment
<vsce-activate-connection>`.
Create a Database and Collection
--------------------------------
Once you connect to your deployment using MongoDB for VS code, use the left
navigation to:
1. Select an active connection and click the :icon-fa5:`plus` icon that
appears.
#. A MongoDB playground automatically opens with a template form to create
a database and a regular collection or a
:ref:`time series collection <vsce-time-series>`.
#. Fill in ``const database`` and ``const collection`` with names of your
database and collection.
#. Uncomment the form of the collection you wish to create.
#. Fill in the collection fields according to your collection's specifications.
#. To run the playground, click the :guilabel:`Play Button` at the top right
of the VS code navigation bar.
After running the playground, the left navigation updates with new database
listed under the active connection it was created. You can find the newly
created collection by expanding the new database.
.. seealso::
- To add documents to the collection, see
:ref:`vsce-create-doc-playground`.
- To learn more about creating time series collections using MongoDB
playgrounds, see :ref:`vsce-time-series`
Example
-------
This example creates a database named ``grades`` and a regular collection
named ``testscores``.
To use this example, start with a template from your MongoDB
Playgrounds:
.. code-block:: javascript
const database = 'grades';
const collection = 'testscores';
use(database);
db.createCollection(collection);
In the example:
- ``const database`` declares the name ``grades`` for the database.
- ``const collection`` declares the name ``testscores`` for the collection.
- ``use(database)`` creates the new ``grades`` database.
- ``db.createCollection(collection)`` creates the collection ``testscores``
inside of the ``grades`` database.
When you press the :guilabel:`Play Button`, MongoDB for VS Code shows the
following results in the ``Playground Results.json`` pane to confirm the
creation of the database and collection.
.. code-block:: javascript
{
"ok": 1
}
The ``grades`` database and ``testscores`` collection also appear in your
left navigation:
.. figure:: /images/vsce-database.png
:figwidth: 200px
:alt: Image showing database and collection
.. toctree::
:titlesonly:
Time Series Collections </time-series-collections>