From e905aede56dc88352eaeb94420de1c4d3f5aa680 Mon Sep 17 00:00:00 2001 From: ian fogelman Date: Fri, 1 Oct 2021 16:09:18 -0400 Subject: [PATCH 1/2] DOCSP-14047 add note about mongoshell to page --- source/faq/fundamentals.txt | 44 +++++++++++++------ .../reference/method/db.createCollection.txt | 3 ++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/source/faq/fundamentals.txt b/source/faq/fundamentals.txt index 63bbc083060..edf83de2b9c 100644 --- a/source/faq/fundamentals.txt +++ b/source/faq/fundamentals.txt @@ -41,35 +41,51 @@ the columns in a relational database table. How do I create a database and a collection? -------------------------------------------- +.. note:: + + You can enter the commands referenced in this FAQ by using + the :doc:`Mongo Shell `. The MongoDB Shell is an + interactive JavaScript interface to MongoDB. You can use the MongoDB + Shell to query and update data as well as perform administrative + operations. + If a database does not exist, MongoDB creates the database when you first store data for that database. If a collection does not exist, MongoDB creates the collection when you -first store data for that collection. [#explicit-creation]_ +first store data for that collection. As such, you can switch to a non-existent database (``use ``) and perform the following operation: .. code-block:: javascript - use myNewDB + use myNewDB; + + db.myNewCollection1.insertOne( { x: 1 } ); + db.myNewCollection2.createIndex( { a: 1 } ); - db.myNewCollection1.insertOne( { x: 1 } ) - db.myNewCollection2.createIndex( { a: 1 } ) +- The :method:`db.collection.insertOne()` method creates + the collection ``myNewCollection1`` if it does not already exist. -The ``insert`` operation creates both the database ``myNewDB`` and the -collection ``myNewCollection1`` if they do not already exist. +- The :method:`db.collection.createIndex()` method creates the index and + the collection ``myNewCollection2`` if it does not already exist. -The ``createIndex`` operation, which occurs after the ``myNewDB`` has -been created, creates the index and the collection ``myNewCollection2`` -if the collection does not exist. If ``myNewDb`` did not exist, the -``createIndex`` operation would have also created the ``myNewDB``. +- If the ``myNewDb`` database did not exist, either the + :method:`db.collection.createIndex()` method or + :method:`db.collection.insertOne()` method would have created + the ``myNewDb`` database automatically. + +You can also create a collection explicitly using +:method:`db.createCollection` method if you want to specify specific +:ref:`options`, such as maximum size +or document validation rules: + +.. code-block:: javascript -.. [#explicit-creation] + use myNewDB; - You can also create a collection explicitly using - :method:`db.createCollection` if you want to specify specific - options, such as maximum size or document validation rules. + db.createCollection("myNewCollection1"); .. _faq-schema-free: diff --git a/source/reference/method/db.createCollection.txt b/source/reference/method/db.createCollection.txt index c9f1c2b1261..ec1f045e381 100644 --- a/source/reference/method/db.createCollection.txt +++ b/source/reference/method/db.createCollection.txt @@ -54,6 +54,9 @@ Definition collation: , writeConcern: } ) + + .. _create_collection_parameters: + The :method:`db.createCollection()` method has the following parameters: From dcc10862eae392154642d33f94384bdc905ed156 Mon Sep 17 00:00:00 2001 From: ian fogelman Date: Fri, 1 Oct 2021 16:09:18 -0400 Subject: [PATCH 2/2] DOCSP-14047 add note about mongoshell to page --- source/faq/fundamentals.txt | 19 ++++++++++++++++--- .../reference/method/db.createCollection.txt | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/source/faq/fundamentals.txt b/source/faq/fundamentals.txt index edf83de2b9c..7474b421661 100644 --- a/source/faq/fundamentals.txt +++ b/source/faq/fundamentals.txt @@ -44,9 +44,9 @@ How do I create a database and a collection? .. note:: You can enter the commands referenced in this FAQ by using - the :doc:`Mongo Shell `. The MongoDB Shell is an - interactive JavaScript interface to MongoDB. You can use the MongoDB - Shell to query and update data as well as perform administrative + the :binary:`~bin.mongo` shell. The mongo shell is an + interactive JavaScript interface to MongoDB. You can use the mongo + shell to query and update data as well as perform administrative operations. If a database does not exist, MongoDB creates the database when you @@ -75,6 +75,7 @@ and perform the following operation: :method:`db.collection.createIndex()` method or :method:`db.collection.insertOne()` method would have created the ``myNewDb`` database automatically. +<<<<<<< HEAD You can also create a collection explicitly using :method:`db.createCollection` method if you want to specify specific @@ -85,6 +86,18 @@ or document validation rules: use myNewDB; +======= + +You can also create a collection explicitly using +:method:`db.createCollection` method if you want to specify specific +:ref:`options`, such as maximum size +or document validation rules: + +.. code-block:: javascript + + use myNewDB; + +>>>>>>> 275b25d49 (DOCSP-14047 add note about mongoshell to page) db.createCollection("myNewCollection1"); .. _faq-schema-free: diff --git a/source/reference/method/db.createCollection.txt b/source/reference/method/db.createCollection.txt index ec1f045e381..d71e6c889ed 100644 --- a/source/reference/method/db.createCollection.txt +++ b/source/reference/method/db.createCollection.txt @@ -55,6 +55,9 @@ Definition writeConcern: } ) + .. _create_collection_parameters: + + .. _create_collection_parameters: The :method:`db.createCollection()` method has the following parameters: