From 318afdfa6e1243c96ab8309aa82e8232992aff39 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 29 Jul 2024 16:51:48 -0400 Subject: [PATCH 1/6] DOCSP-41557: v4.7 commands and methods --- docs/fundamentals/database-collection.txt | 98 +++++++++++++++++++++-- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/docs/fundamentals/database-collection.txt b/docs/fundamentals/database-collection.txt index 6b629d79e..9dfdc87aa 100644 --- a/docs/fundamentals/database-collection.txt +++ b/docs/fundamentals/database-collection.txt @@ -161,17 +161,105 @@ as in the preceding example, but the query is constructed by using the List Collections ---------------- -To see information about each of the collections in a database, call the -``listCollections()`` method. +This section describes how to see information about each collection in a database +in the following ways: -The following example accesses a database connection, then -calls the ``listCollections()`` method to retrieve information about the -collections in the database: +- :ref:`laravel-list-coll-command` +- :ref:`laravel-list-coll-methods` + +.. _laravel-list-coll-command: + +Run a Shell Command +~~~~~~~~~~~~~~~~~~~ + +You can list the collections in a database by running the following shell +command from your project root: + +.. code-block:: bash + + php artisan db:show + +This command outputs information about the configured database and lists its +collections under the ``Table`` header. For more information about the ``db:show`` +command, see `Laravel: New DB Commands `__. + +.. _laravel-list-coll-methods: + +Call Database or Schema Methods +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can list the collections in a database by calling the following +methods in your application: + +- ``DB::listCollections()``: lists information about each collection by + using the query builder +- ``Schema::getTablesListing()``: lists the name of each collection by + using the schema builder +- ``Schema::getTables()``: lists the name and size of each collection by + using the schema builder + +Example +``````` + +The following example accesses a database connection, then calls the +``listCollections()`` query builder method to retrieve information about +the collections in the database: .. code-block:: php $collections = DB::connection('mongodb')->getMongoDB()->listCollections(); +List Collection Fields +---------------------- + +This section describes how to see information about each field in a collection +in the following ways: + +- :ref:`laravel-list-fields-command` +- :ref:`laravel-list-fields-methods` + +.. _laravel-list-fields-command: + +Run a Shell Command +~~~~~~~~~~~~~~~~~~~ + +You can see a list of fields in a collection by running the following shell +command from your project root: + +.. code-block:: bash + + php artisan db:table + +This command outputs each collection field and its corresponding data type +under the ``Column`` header. For more information about the ``db:table`` +command, see `Laravel: New DB Commands `__. + +.. _laravel-list-fields-methods: + +Call Schema Methods +~~~~~~~~~~~~~~~~~~~ + +You can list the collections in a database by calling the ``Schema::getColumns()`` +schema builder method in your application. + +You can also call the following methods to return more information about the +collection fields: + +- ``Schema::hasColumn(string $field)``: checks if the specified field exists + in at least one document +- ``Schema::hasColumns(string[] $fields)``: checks if each specified field exists + in at least one document + +Example +``````` + +The following example passes a collection name to the ``Schema::getColumns()`` +method to retrieve each field in the ``flowers`` collection: + +.. code-block:: php + + $fields = Schema::getColumns('flowers'); + Create and Drop Collections --------------------------- From b0af0c1bab815025a9dfd613c9a443d0e6582dba Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 29 Jul 2024 16:59:48 -0400 Subject: [PATCH 2/6] reword, fixes --- docs/fundamentals/database-collection.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/database-collection.txt b/docs/fundamentals/database-collection.txt index 9dfdc87aa..f84a61ec5 100644 --- a/docs/fundamentals/database-collection.txt +++ b/docs/fundamentals/database-collection.txt @@ -192,11 +192,11 @@ You can list the collections in a database by calling the following methods in your application: - ``DB::listCollections()``: lists information about each collection by - using the query builder + using the query builder - ``Schema::getTablesListing()``: lists the name of each collection by - using the schema builder + using the schema builder - ``Schema::getTables()``: lists the name and size of each collection by - using the schema builder + using the schema builder Example ``````` @@ -239,7 +239,7 @@ command, see `Laravel: New DB Commands Date: Wed, 31 Jul 2024 09:27:59 -0400 Subject: [PATCH 3/6] RR feedback --- docs/fundamentals/database-collection.txt | 28 ++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/fundamentals/database-collection.txt b/docs/fundamentals/database-collection.txt index f84a61ec5..8dec27491 100644 --- a/docs/fundamentals/database-collection.txt +++ b/docs/fundamentals/database-collection.txt @@ -161,8 +161,8 @@ as in the preceding example, but the query is constructed by using the List Collections ---------------- -This section describes how to see information about each collection in a database -in the following ways: +You can take either of the following actions to see information +about the collections in a database: - :ref:`laravel-list-coll-command` - :ref:`laravel-list-coll-methods` @@ -172,8 +172,8 @@ in the following ways: Run a Shell Command ~~~~~~~~~~~~~~~~~~~ -You can list the collections in a database by running the following shell -command from your project root: +You can list the collections in a database by running the following +command in your shell from your project's root directory: .. code-block:: bash @@ -181,7 +181,8 @@ command from your project root: This command outputs information about the configured database and lists its collections under the ``Table`` header. For more information about the ``db:show`` -command, see `Laravel: New DB Commands `__. +command, see `Laravel: New DB Commands `__ +on the official Laravel blog. .. _laravel-list-coll-methods: @@ -212,8 +213,8 @@ the collections in the database: List Collection Fields ---------------------- -This section describes how to see information about each field in a collection -in the following ways: +You can take either of the following actions to see information +about each field in a collection: - :ref:`laravel-list-fields-command` - :ref:`laravel-list-fields-methods` @@ -223,8 +224,8 @@ in the following ways: Run a Shell Command ~~~~~~~~~~~~~~~~~~~ -You can see a list of fields in a collection by running the following shell -command from your project root: +You can see a list of fields in a collection by running the following +command in your shell from your project's root directory: .. code-block:: bash @@ -232,7 +233,8 @@ command from your project root: This command outputs each collection field and its corresponding data type under the ``Column`` header. For more information about the ``db:table`` -command, see `Laravel: New DB Commands `__. +command, see `Laravel: New DB Commands `__ +on the official Laravel blog. .. _laravel-list-fields-methods: @@ -242,12 +244,12 @@ Call Schema Methods You can list the fields in a collection by calling the ``Schema::getColumns()`` schema builder method in your application. -You can also call the following methods to return more information about the +You can also use the following methods to return more information about the collection fields: -- ``Schema::hasColumn(string $field)``: checks if the specified field exists +- ``Schema::hasColumn(string $)``: checks if the specified field exists in at least one document -- ``Schema::hasColumns(string[] $fields)``: checks if each specified field exists +- ``Schema::hasColumns(string[] $)``: checks if each specified field exists in at least one document Example From fd0c6c9bd30d8a5cc52543df1dcd6085e19d271b Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 12 Aug 2024 14:40:06 -0400 Subject: [PATCH 4/6] JT review --- docs/fundamentals/database-collection.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/fundamentals/database-collection.txt b/docs/fundamentals/database-collection.txt index 8dec27491..f5a3c5b6d 100644 --- a/docs/fundamentals/database-collection.txt +++ b/docs/fundamentals/database-collection.txt @@ -247,11 +247,17 @@ schema builder method in your application. You can also use the following methods to return more information about the collection fields: -- ``Schema::hasColumn(string $)``: checks if the specified field exists +- ``Schema::hasColumn(string $, string $)``: checks if the specified field exists in at least one document -- ``Schema::hasColumns(string[] $)``: checks if each specified field exists +- ``Schema::hasColumns(string $, string[] $)``: checks if each specified field exists in at least one document +.. note:: + + MongoDB is a schemaless database, so the preceding functions query the specified + collection rather than the database schema. If the collection doesn't exist + or is empty, these functions return a value of ``false``. + Example ``````` From 3bd4511491bb0b1c634e1044e274e9669b88f214 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 12 Aug 2024 14:48:39 -0400 Subject: [PATCH 5/6] wording --- docs/fundamentals/database-collection.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/fundamentals/database-collection.txt b/docs/fundamentals/database-collection.txt index f5a3c5b6d..db79e99f8 100644 --- a/docs/fundamentals/database-collection.txt +++ b/docs/fundamentals/database-collection.txt @@ -199,6 +199,11 @@ methods in your application: - ``Schema::getTables()``: lists the name and size of each collection by using the schema builder +.. note:: + + MongoDB is a schemaless database, so the preceding schema builder functions + query the database data rather than the schema. + Example ``````` @@ -254,8 +259,8 @@ collection fields: .. note:: - MongoDB is a schemaless database, so the preceding functions query the specified - collection rather than the database schema. If the collection doesn't exist + MongoDB is a schemaless database, so the preceding functions query the collection + data rather than the database schema. If the specified collection doesn't exist or is empty, these functions return a value of ``false``. Example From 9a2d6faf644aaf17577b5e47056d19fb6ec35900 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 12 Aug 2024 14:50:32 -0400 Subject: [PATCH 6/6] fix --- docs/fundamentals/database-collection.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/fundamentals/database-collection.txt b/docs/fundamentals/database-collection.txt index db79e99f8..7bbae4786 100644 --- a/docs/fundamentals/database-collection.txt +++ b/docs/fundamentals/database-collection.txt @@ -201,7 +201,7 @@ methods in your application: .. note:: - MongoDB is a schemaless database, so the preceding schema builder functions + MongoDB is a schemaless database, so the preceding schema builder methods query the database data rather than the schema. Example @@ -259,9 +259,9 @@ collection fields: .. note:: - MongoDB is a schemaless database, so the preceding functions query the collection + MongoDB is a schemaless database, so the preceding methods query the collection data rather than the database schema. If the specified collection doesn't exist - or is empty, these functions return a value of ``false``. + or is empty, these methods return a value of ``false``. Example ```````