Skip to content

Commit 0517fca

Browse files
DOCSP-25448 Create a Collection in MongoDB SEO Optimizations (#6829)
* DOCSP-25448 Create a Collection in MongoDB SEO Optimizations * DOCSP-25448 updates for copy feedback * DOCSP-25448 updates for SEO * DOCSP-25448 updates for EG's feedback
1 parent d7901e6 commit 0517fca

File tree

1 file changed

+270
-43
lines changed

1 file changed

+270
-43
lines changed

source/core/databases-and-collections.txt

Lines changed: 270 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _databases-and-collections:
22

3-
=========================
4-
Databases and Collections
5-
=========================
3+
====================================
4+
Databases and Collections in MongoDB
5+
====================================
66

77
.. default-domain:: mongodb
88

@@ -22,8 +22,8 @@ Databases and Collections
2222
:values: reference
2323

2424
.. meta::
25-
:description: Overview of what databases and collections (tables) are in MongoDB.
26-
:keywords: atlas
25+
:description: Learn how databases and collections work within MongoDB
26+
:keywords: atlas, compass, MongoDB
2727

2828
.. contents:: On this page
2929
:local:
@@ -33,48 +33,154 @@ Databases and Collections
3333

3434
Overview
3535
--------
36+
3637
MongoDB stores data records as :term:`documents <document>`
3738
(specifically :ref:`BSON documents <bson-document-format>`) which are
3839
gathered together in :term:`collections <collection>`. A
3940
:term:`database <database>` stores one or more collections of documents.
4041

41-
.. |page-topic| replace:: manage MongoDB :atlas:`databases </atlas-ui/databases>` and :atlas:`collections </atlas-ui/collections>` in the UI
42+
You can manage :atlas:`databases </atlas-ui/databases>` and
43+
:atlas:`collections </atlas-ui/collections>` on the Atlas cluster from
44+
the Atlas UI, :binary:`~bin.mongosh`, or |compass|. This page describes
45+
how to manage databases and collections on the Atlas cluster from the
46+
Atlas UI. For self-managed deployments, you can use
47+
:binary:`~bin.mongosh` or |compass| to manage databases and collections.
48+
49+
Select the client that you want to use to manage databases and
50+
collections.
51+
52+
.. tabs::
53+
54+
.. tab:: Atlas UI
55+
:tabid: atlas
56+
57+
MongoDB Atlas is a multi-cloud database service that simplifies
58+
deploying and managing your databases on the cloud providers of
59+
your choice.
60+
61+
.. tab:: mongosh
62+
:tabid: mongosh
4263

43-
.. cta-banner::
44-
:url: https://www.mongodb.com/docs/atlas/atlas-ui/databases/
45-
:icon: Cloud
64+
The MongoDB Shell, :program:`mongosh`, is a JavaScript and Node.js
65+
:abbr:`REPL (Read Eval Print Loop)` environment for interacting
66+
with MongoDB deployments. To learn more, see :mongosh:`mongosh
67+
</>`.
4668

47-
.. include:: /includes/fact-atlas-compatible.rst
69+
.. tab:: MongoDB Compass
70+
:tabid: compass
4871

72+
MongoDB Compass is a powerful GUI for querying, aggregating, and
73+
analyzing your MongoDB data in a visual environment. To learn
74+
more, see :compass:`MongoDB Compass </>`.
4975

5076
Databases
5177
---------
52-
In MongoDB, databases hold one or more collections of documents. To
53-
select a database to use, in :binary:`~bin.mongosh`, issue the
54-
``use <db>`` statement, as in the following example:
5578

56-
.. code-block:: javascript
79+
In MongoDB, databases hold one or more collections of documents.
80+
81+
.. tabs::
82+
:hidden:
83+
84+
.. tab:: Atlas UI
85+
:tabid: atlas
86+
87+
To select a database to use, log in to Atlas and do the following:
88+
89+
.. procedure::
90+
:style: normal
5791

58-
use myDB
92+
.. step:: Navigate to the :guilabel:`Collections` tab.
5993

94+
.. step:: Select the database from the list of databases in the left pane.
95+
96+
.. tab:: mongosh
97+
:tabid: mongosh
98+
99+
To select a database to use, in :binary:`~bin.mongosh`, issue the
100+
``use <db>`` statement, as in the following example:
101+
102+
.. code-block:: javascript
103+
104+
use myDB
105+
106+
.. tab:: MongoDB Compass
107+
:tabid: compass
108+
109+
To select a database to use, complete the following steps:
110+
111+
.. procedure::
112+
:style: normal
113+
114+
.. step:: Start |compass| and connect to your cluster.
115+
116+
To learn more, see :compass:`Connect to MongoDB
117+
</connect/>`.
118+
119+
.. step:: Select :guilabel:`Databases` from the left navigation.
120+
121+
The :guilabel:`Databases` tab opens to list the existing databases
122+
for your MongoDB deployment.
123+
60124
Create a Database
61125
~~~~~~~~~~~~~~~~~
62126

63-
If a database does not exist, MongoDB creates the database when you
64-
first store data for that database. As such, you can switch to a
65-
non-existent database and perform the following operation in
66-
:binary:`~bin.mongosh`:
127+
.. tabs::
128+
:hidden:
67129

68-
.. code-block:: javascript
130+
.. tab:: Atlas UI
131+
:tabid: atlas
69132

70-
use myNewDB
133+
To create a new database, log in to Atlas and do the following:
71134

72-
db.myNewCollection1.insertOne( { x: 1 } )
135+
.. procedure::
136+
:style: normal
73137

74-
The :method:`~db.collection.insertOne()` operation creates both the
75-
database ``myNewDB`` and the collection ``myNewCollection1`` if they do
76-
not already exist. Be sure that both the database and collection names
77-
follow MongoDB :ref:`restrictions-on-db-names`.
138+
.. step:: Navigate to the :guilabel:`Collections` tab.
139+
140+
.. step:: Click :guilabel:`Create Database`.
141+
142+
.. step:: Enter the :guilabel:`Database Name` and the :guilabel:`Collection Name`.
143+
144+
Enter the database and the collection name to create the
145+
database and its first collection.
146+
147+
.. step:: Click :guilabel:`Create`.
148+
149+
Upon successful creation, the database and the collection
150+
displays in the left pane in the Atlas UI.
151+
152+
.. tab:: mongosh
153+
:tabid: mongosh
154+
155+
If a database does not exist, MongoDB creates the database when you
156+
first store data for that database. As such, you can switch to a
157+
non-existent database and perform the following operation in
158+
:binary:`~bin.mongosh`:
159+
160+
.. code-block:: javascript
161+
162+
use myNewDB
163+
164+
db.myNewCollection1.insertOne( { x: 1 } )
165+
166+
The :method:`~db.collection.insertOne()` operation creates both the
167+
database ``myNewDB`` and the collection ``myNewCollection1`` if they do
168+
not already exist. Be sure that both the database and collection names
169+
follow MongoDB :ref:`restrictions-on-db-names`.
170+
171+
.. tab:: MongoDB Compass
172+
:tabid: compass
173+
174+
.. procedure::
175+
:style: normal
176+
177+
.. step:: Open the :guilabel:`Databases` tab.
178+
179+
.. step:: Click the :guilabel:`Create database` button.
180+
181+
.. step:: Enter database and first collection names in the :guilabel:`Create Database` dialog.
182+
183+
.. step:: Click :guilabel:`Create Database` to create the database and its first collection.
78184

79185
.. _collections:
80186

@@ -92,27 +198,136 @@ Create a Collection
92198
If a collection does not exist, MongoDB creates the collection when you
93199
first store data for that collection.
94200

95-
.. code-block:: javascript
201+
.. tabs::
202+
:hidden:
203+
204+
.. tab:: Atlas
205+
:tabid: atlas
206+
207+
To create a new collection, log in to Atlas and do the following:
208+
209+
.. procedure::
210+
:style: normal
96211

97-
db.myNewCollection2.insertOne( { x: 1 } )
98-
db.myNewCollection3.createIndex( { y: 1 } )
212+
.. step:: Navigate to the :guilabel:`Collections` tab.
99213

100-
Both the :method:`~db.collection.insertOne()` and the
101-
:method:`~db.collection.createIndex()` operations create their
102-
respective collection if they do not already exist. Be sure that the
103-
collection name follows MongoDB :ref:`restrictions-on-db-names`.
214+
.. step:: Click the :guilabel:`+` icon for the database.
215+
216+
.. step:: Enter the name of the collection.
217+
218+
.. step:: Click :guilabel:`Create`.
219+
220+
Upon successful creation, the collection displays underneath
221+
the database in the Atlas UI.
222+
223+
.. tab:: mongosh
224+
:tabid: mongosh
225+
226+
.. code-block:: javascript
227+
228+
db.myNewCollection2.insertOne( { x: 1 } )
229+
db.myNewCollection3.createIndex( { y: 1 } )
230+
231+
Both the :method:`~db.collection.insertOne()` and the
232+
:method:`~db.collection.createIndex()` operations create their
233+
respective collection if they do not already exist. Be sure that the
234+
collection name follows MongoDB :ref:`restrictions-on-db-names`.
235+
236+
.. tab:: MongoDB Compass
237+
:tabid: compass
238+
239+
.. procedure::
240+
:style: normal
241+
242+
.. step:: Click the name of the database where you to want to create a collection in the left navigation.
243+
244+
.. step:: Click the :guilabel:`+` icon next to the database name.
245+
246+
.. step:: Enter the name of the collection in the :guilabel:`Create Collection` dialog.
247+
248+
.. step:: Click :guilabel:`Create Collection` to create the collection.
104249

105250
Explicit Creation
106251
~~~~~~~~~~~~~~~~~
107252

108-
MongoDB provides the :method:`db.createCollection()` method to
109-
explicitly create a collection with various options, such as setting
110-
the maximum size or the documentation validation rules. If you are not
111-
specifying these options, you do not need to explicitly create the
112-
collection since MongoDB creates new collections when you first store
113-
data for the collections.
253+
.. tabs::
254+
:hidden:
255+
256+
.. tab:: Atlas
257+
:tabid: atlas
258+
259+
To create a new collection, log in to Atlas and do the following:
260+
261+
.. procedure::
262+
:style: normal
263+
264+
.. step:: Navigate to the :guilabel:`Collections` tab.
265+
266+
.. step:: Click the :guilabel:`+` icon for the database.
267+
268+
.. step:: Enter the name of the collection.
269+
270+
.. step:: Optional. From the :guilabel:`Additional Preferences` dropdown, select the type of collection that you want to create.
271+
272+
You can create one of the following types of collections:
273+
274+
- :ref:`Capped collection <manual-capped-collection>`
114275

115-
To modify these collection options, see :dbcommand:`collMod`.
276+
If you select to create a capped collection, specify the
277+
maximum size in bytes.
278+
279+
- :ref:`Time Series Collection <manual-timeseries-landing>`
280+
281+
If you select to create a time series collection, specify
282+
the time field and granularity. You can optionally specify
283+
the meta field and the time for old data in the collection
284+
to expire.
285+
286+
- :ref:`Clustered Index Collection <clustered-collections>`
287+
288+
If you select to create a clustered collection, you must
289+
specify clustered index key value and a name for the
290+
clustered index.
291+
292+
.. step:: Click :guilabel:`Create`.
293+
294+
Upon successful creation, the collection displays underneath
295+
the database in the Atlas UI.
296+
297+
.. tab:: mongosh
298+
:tabid: mongosh
299+
300+
MongoDB provides the :method:`db.createCollection()` method to
301+
explicitly create a collection with various options, such as setting
302+
the maximum size or the documentation validation rules. If you are not
303+
specifying these options, you do not need to explicitly create the
304+
collection since MongoDB creates new collections when you first store
305+
data for the collections.
306+
307+
To modify these collection options, see :dbcommand:`collMod`.
308+
309+
.. tab:: MongoDB Compass
310+
:tabid: compass
311+
312+
.. procedure::
313+
:style: normal
314+
315+
.. step:: Click the name of the database where you to want to create a collection in the left navigation.
316+
317+
.. step:: Click the :guilabel:`Create collection` button.
318+
319+
.. step:: Enter the name of the collection and optionally, configure additional preferences.
320+
321+
.. step:: Click :guilabel:`Create Collection` to create the collection.
322+
323+
|compass| provides the following additional preferences that
324+
you can configure for your collection:
325+
326+
- :compass:`Create a Capped Collection</collections/capped-collection/>`
327+
- :compass:`Create a Clustered Collection</collections/clustered-collection/>`
328+
- :compass:`Create a Collection with Collation </collections/collation-collection/>`
329+
- :compass:`Create a Collection with Encrypted Field </collections/encrypted-collection/>`
330+
- :compass:`Create a Time Series Collection </collections/time-series-collection/>`
116331

117332
Document Validation
118333
~~~~~~~~~~~~~~~~~~~
@@ -151,9 +366,21 @@ identifier)`. The
151366
collection UUID remains the same across all members of a replica set
152367
and shards in a sharded cluster.
153368

154-
To retrieve the UUID for a collection, run either the
155-
:manual:`listCollections </reference/command/listCollections>` command
156-
or the :method:`db.getCollectionInfos()` method.
369+
.. tabs::
370+
:hidden:
371+
372+
.. tab:: Atlas
373+
:tabid: atlas
374+
375+
.. tab:: mongosh
376+
:tabid: mongosh
377+
378+
To retrieve the UUID for a collection, run either the
379+
:manual:`listCollections </reference/command/listCollections>` command
380+
or the :method:`db.getCollectionInfos()` method.
381+
382+
.. tab:: MongoDB Compass
383+
:tabid: compass
157384

158385
.. toctree::
159386
:titlesonly:

0 commit comments

Comments
 (0)