Skip to content

Commit 1090816

Browse files
ianf-mongodbjeff-allen-mongo
authored andcommitted
DOCSP-14047 add note about mongoshell to page
1 parent 48d59b6 commit 1090816

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

source/faq/fundamentals.txt

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,51 @@ the columns in a relational database table.
4141
How do I create a database and a collection?
4242
--------------------------------------------
4343

44+
.. note::
45+
46+
You can enter the commands referenced in this FAQ by using
47+
the :binary:`~bin.mongo` shell. The mongo shell is an
48+
interactive JavaScript interface to MongoDB. You can use the mongo
49+
shell to query and update data as well as perform administrative
50+
operations.
51+
4452
If a database does not exist, MongoDB creates the database when you
4553
first store data for that database.
4654

4755
If a collection does not exist, MongoDB creates the collection when you
48-
first store data for that collection. [#explicit-creation]_
56+
first store data for that collection.
4957

5058
As such, you can switch to a non-existent database (``use <dbname>``)
5159
and perform the following operation:
5260

5361
.. code-block:: javascript
5462

55-
use myNewDB
63+
use myNewDB;
64+
65+
db.myNewCollection1.insertOne( { x: 1 } );
66+
db.myNewCollection2.createIndex( { a: 1 } );
5667

57-
db.myNewCollection1.insertOne( { x: 1 } )
58-
db.myNewCollection2.createIndex( { a: 1 } )
68+
- The :method:`db.collection.insertOne()` method creates
69+
the collection ``myNewCollection1`` if it does not already exist.
5970

60-
The ``insert`` operation creates both the database ``myNewDB`` and the
61-
collection ``myNewCollection1`` if they do not already exist.
71+
- The :method:`db.collection.createIndex()` method creates the index and
72+
the collection ``myNewCollection2`` if it does not already exist.
6273

63-
The ``createIndex`` operation, which occurs after the ``myNewDB`` has
64-
been created, creates the index and the collection ``myNewCollection2``
65-
if the collection does not exist. If ``myNewDb`` did not exist, the
66-
``createIndex`` operation would have also created the ``myNewDB``.
74+
- If the ``myNewDb`` database did not exist, either the
75+
:method:`db.collection.createIndex()` method or
76+
:method:`db.collection.insertOne()` method would have created
77+
the ``myNewDb`` database automatically.
78+
79+
You can also create a collection explicitly using
80+
:method:`db.createCollection` method if you want to specify specific
81+
:ref:`options<create_collection_parameters>`, such as maximum size
82+
or document validation rules:
83+
84+
.. code-block:: javascript
6785

68-
.. [#explicit-creation]
86+
use myNewDB;
6987

70-
You can also create a collection explicitly using
71-
:method:`db.createCollection` if you want to specify specific
72-
options, such as maximum size or document validation rules.
88+
db.createCollection("myNewCollection1");
7389

7490
.. _faq-schema-free:
7591

source/reference/method/db.createCollection.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Definition
5757
}
5858
)
5959

60+
61+
.. _create_collection_parameters:
62+
6063
The :method:`db.createCollection()` method has the following parameters:
6164

6265

0 commit comments

Comments
 (0)