From d46295c17cb023f3f65565b1c12e866c72e4cd2a Mon Sep 17 00:00:00 2001 From: Pavel Duchovny Date: Tue, 18 Jun 2024 09:34:43 +0300 Subject: [PATCH 1/8] Adding NoSQL and MongoDB content --- _posts/07-06-01-NoSql_Databases.md | 24 ++++++++++ _posts/07-07-01-Databases_MongoDB.md | 69 ++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 _posts/07-06-01-NoSql_Databases.md create mode 100644 _posts/07-07-01-Databases_MongoDB.md diff --git a/_posts/07-06-01-NoSql_Databases.md b/_posts/07-06-01-NoSql_Databases.md new file mode 100644 index 000000000..6c3a2e443 --- /dev/null +++ b/_posts/07-06-01-NoSql_Databases.md @@ -0,0 +1,24 @@ +--- +isChild: true +title: Introduction to NoSQL Databases +anchor: databases_nosql +--- + +## Introduction to NoSQL Databases +{#databases_nosql_title} + +NoSQL databases provide a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases. They are increasingly used in big data and real-time web applications. NoSQL databases are generally categorized under four types: + +1. **Document Databases**: Store data in documents similar to JSON (JavaScript Object Notation) objects. Example: MongoDB. +2. **Key-Value Stores**: Data is stored as a collection of key-value pairs. Example: Redis. +3. **Column-Oriented Databases**: Data is stored in columns instead of rows. Example: Apache Cassandra. +4. **Graph Databases**: Store data in graph structures with nodes, edges, and properties. Example: Neo4j. + +MongoDB being the leading NoSQL database can work + +## Why NoSQL? + +- **Flexibility**: NoSQL databases often use flexible data models, allowing for more rapid changes and iterations. +- **Scalability**: Designed to scale out by distributing data across multiple servers. +- **Performance**: Optimized for specific data models and access patterns, often resulting in faster queries. + diff --git a/_posts/07-07-01-Databases_MongoDB.md b/_posts/07-07-01-Databases_MongoDB.md new file mode 100644 index 000000000..0abafecff --- /dev/null +++ b/_posts/07-07-01-Databases_MongoDB.md @@ -0,0 +1,69 @@ +--- +isChild: true +title: MongoDB +anchor: databases_mongodb +--- + +## MongoDB +{#databases_mongodb_title} + +[MongoDB][1] is a leading NoSQL database that stores data in JSON-like documents, providing flexibility and scalability for various application needs. MongoDB can support multiple data models, making it versatile for different use cases. + +### Features of MongoDB + +- **Document Model**: Uses a JSON-like format to store data, which is more expressive and flexible. +- **Scalability**: Supports horizontal scaling through sharding. +- **Aggregation Framework**: Powerful querying and data aggregation capabilities. +- **High Performance**: Optimized for read and write operations. +- **Multi-Model Support**: MongoDB can support key-value, graph, and time-series data models, providing a comprehensive solution for various data needs. + +### MongoDB as a Multi-Model Database + +- **Key-Value Data**: MongoDB's flexible schema allows it to efficiently store key-value pairs, making it suitable for caching and session storage. +- **Graph Data**: MongoDB supports graph processing and storage through its rich document model, enabling complex relationships and queries similar to graph databases. +- **Time-Series Data**: MongoDB's native support for time-series data, with features like time-series collections, makes it ideal for IoT, financial data, and other applications requiring efficient time-based data storage and querying. + +### MongoDB and PHP + +MongoDB provides a robust driver for PHP, enabling developers to interact with MongoDB databases from their PHP applications. + +#### Installing the MongoDB PHP Driver + +To install the MongoDB PHP driver, you can use the following commands: + +```shell +# Install the MongoDB extension for PHP +sudo pecl install mongodb + +# Enable the extension in your php.ini file +echo "extension=mongodb.so" ... +``` + +#### Using the MongoDB PHP Library +Once the driver is installed, you can use the MongoDB PHP library to connect to your MongoDB database and perform operations. Here's an example: + +```php +demo->beers; + +// Insert a document +$result = $collection->insertOne(['name' => 'Hinterland', 'brewery' => 'Coopers', 'abv' => 5.5]); +echo "Inserted with Object ID '{$result->getInsertedId()}'"; + +// Query a document +$beer = $collection->findOne(['name' => 'Hinterland']); +echo "Beer: ", $beer['name'], " Brewery: ", $beer['brewery'], " ABV: ", $beer['abv'], "\n"; + +?> +``` + + +For more information, refer to the official [MongoDB PHP documentation][2]. + + +[1]: https://www.mongodb.com/ +[2]: https://www.mongodb.com/docs/drivers/php-drivers/ \ No newline at end of file From bca508b7a8c28e4ee3d9f5b9c7b27450519c4285 Mon Sep 17 00:00:00 2001 From: Pavel Duchovny Date: Tue, 18 Jun 2024 09:37:33 +0300 Subject: [PATCH 2/8] Fixing anchor --- _posts/07-06-01-NoSql_Databases.md | 3 +-- _posts/07-07-01-Databases_MongoDB.md | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/_posts/07-06-01-NoSql_Databases.md b/_posts/07-06-01-NoSql_Databases.md index 6c3a2e443..aa065c882 100644 --- a/_posts/07-06-01-NoSql_Databases.md +++ b/_posts/07-06-01-NoSql_Databases.md @@ -4,8 +4,7 @@ title: Introduction to NoSQL Databases anchor: databases_nosql --- -## Introduction to NoSQL Databases -{#databases_nosql_title} +## Introduction to NoSQL Databases {#databases_nosql_title} NoSQL databases provide a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases. They are increasingly used in big data and real-time web applications. NoSQL databases are generally categorized under four types: diff --git a/_posts/07-07-01-Databases_MongoDB.md b/_posts/07-07-01-Databases_MongoDB.md index 0abafecff..ec3b9b772 100644 --- a/_posts/07-07-01-Databases_MongoDB.md +++ b/_posts/07-07-01-Databases_MongoDB.md @@ -4,8 +4,7 @@ title: MongoDB anchor: databases_mongodb --- -## MongoDB -{#databases_mongodb_title} +## MongoDB {#databases_mongodb_title} [MongoDB][1] is a leading NoSQL database that stores data in JSON-like documents, providing flexibility and scalability for various application needs. MongoDB can support multiple data models, making it versatile for different use cases. From e04ec05b166120f9d5aa387756bebc6c3fcc7a86 Mon Sep 17 00:00:00 2001 From: Pavel Duchovny Date: Tue, 18 Jun 2024 09:41:10 +0300 Subject: [PATCH 3/8] Fixing a typo --- _posts/07-06-01-NoSql_Databases.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/_posts/07-06-01-NoSql_Databases.md b/_posts/07-06-01-NoSql_Databases.md index aa065c882..afc7d8035 100644 --- a/_posts/07-06-01-NoSql_Databases.md +++ b/_posts/07-06-01-NoSql_Databases.md @@ -13,8 +13,6 @@ NoSQL databases provide a mechanism for storage and retrieval of data that is mo 3. **Column-Oriented Databases**: Data is stored in columns instead of rows. Example: Apache Cassandra. 4. **Graph Databases**: Store data in graph structures with nodes, edges, and properties. Example: Neo4j. -MongoDB being the leading NoSQL database can work - ## Why NoSQL? - **Flexibility**: NoSQL databases often use flexible data models, allowing for more rapid changes and iterations. From 8f978ed1b2a0753632c05e94f3323765d5965c68 Mon Sep 17 00:00:00 2001 From: Pavel Duchovny Date: Tue, 18 Jun 2024 09:44:47 +0300 Subject: [PATCH 4/8] Adding Indexing section --- _posts/07-07-01-Databases_MongoDB.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/_posts/07-07-01-Databases_MongoDB.md b/_posts/07-07-01-Databases_MongoDB.md index ec3b9b772..b024fda47 100644 --- a/_posts/07-07-01-Databases_MongoDB.md +++ b/_posts/07-07-01-Databases_MongoDB.md @@ -14,6 +14,12 @@ anchor: databases_mongodb - **Scalability**: Supports horizontal scaling through sharding. - **Aggregation Framework**: Powerful querying and data aggregation capabilities. - **High Performance**: Optimized for read and write operations. + +Sure, here's a revised version of the sentence: + +markdown +Copy code +- **Advanced Indexing**: MongoDB offers a comprehensive range of indexing options, including standard compound indexes, text indexes, vector indexes, and geospatial indexes. - **Multi-Model Support**: MongoDB can support key-value, graph, and time-series data models, providing a comprehensive solution for various data needs. ### MongoDB as a Multi-Model Database From 12ad319a9ba8d7ff49e4f469bfa33acca965a25f Mon Sep 17 00:00:00 2001 From: Pavel Duchovny Date: Tue, 18 Jun 2024 09:47:42 +0300 Subject: [PATCH 5/8] Adding Indexing section --- _posts/07-07-01-Databases_MongoDB.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/_posts/07-07-01-Databases_MongoDB.md b/_posts/07-07-01-Databases_MongoDB.md index b024fda47..0a9e51838 100644 --- a/_posts/07-07-01-Databases_MongoDB.md +++ b/_posts/07-07-01-Databases_MongoDB.md @@ -14,11 +14,6 @@ anchor: databases_mongodb - **Scalability**: Supports horizontal scaling through sharding. - **Aggregation Framework**: Powerful querying and data aggregation capabilities. - **High Performance**: Optimized for read and write operations. - -Sure, here's a revised version of the sentence: - -markdown -Copy code - **Advanced Indexing**: MongoDB offers a comprehensive range of indexing options, including standard compound indexes, text indexes, vector indexes, and geospatial indexes. - **Multi-Model Support**: MongoDB can support key-value, graph, and time-series data models, providing a comprehensive solution for various data needs. From 6c32c9cb2ef3ec539bca685514f56dc448837cc4 Mon Sep 17 00:00:00 2001 From: Pavel Duchovny Date: Tue, 18 Jun 2024 09:52:05 +0300 Subject: [PATCH 6/8] php.ini code --- _posts/07-07-01-Databases_MongoDB.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/07-07-01-Databases_MongoDB.md b/_posts/07-07-01-Databases_MongoDB.md index 0a9e51838..09a0edde2 100644 --- a/_posts/07-07-01-Databases_MongoDB.md +++ b/_posts/07-07-01-Databases_MongoDB.md @@ -36,7 +36,7 @@ To install the MongoDB PHP driver, you can use the following commands: sudo pecl install mongodb # Enable the extension in your php.ini file -echo "extension=mongodb.so" ... +echo "extension=mongodb.so" >> /php.ini ``` #### Using the MongoDB PHP Library From cb305890c2f45aeade2c765108d802cc080f18af Mon Sep 17 00:00:00 2001 From: Pavel Duchovny Date: Tue, 18 Jun 2024 10:57:21 +0300 Subject: [PATCH 7/8] Fix php code --- _posts/07-07-01-Databases_MongoDB.md | 33 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/_posts/07-07-01-Databases_MongoDB.md b/_posts/07-07-01-Databases_MongoDB.md index 09a0edde2..a5ebc7948 100644 --- a/_posts/07-07-01-Databases_MongoDB.md +++ b/_posts/07-07-01-Databases_MongoDB.md @@ -29,7 +29,7 @@ MongoDB provides a robust driver for PHP, enabling developers to interact with M #### Installing the MongoDB PHP Driver -To install the MongoDB PHP driver, you can use the following commands: +To install the MongoDB PHP extension, you can use the following commands: ```shell # Install the MongoDB extension for PHP @@ -39,25 +39,38 @@ sudo pecl install mongodb echo "extension=mongodb.so" >> /php.ini ``` +To install the MongoDB Driver, you can use the following command: +```shell +composer require mongodb/mongodb +``` + #### Using the MongoDB PHP Library Once the driver is installed, you can use the MongoDB PHP library to connect to your MongoDB database and perform operations. Here's an example: ```php demo->beers; +// Replace the placeholder with your Atlas connection string +$uri = ''; -// Insert a document -$result = $collection->insertOne(['name' => 'Hinterland', 'brewery' => 'Coopers', 'abv' => 5.5]); -echo "Inserted with Object ID '{$result->getInsertedId()}'"; +// Create a new client and connect to the server +$client = new Client($uri); +try { + $collection = $client->demo->beers; -// Query a document -$beer = $collection->findOne(['name' => 'Hinterland']); -echo "Beer: ", $beer['name'], " Brewery: ", $beer['brewery'], " ABV: ", $beer['abv'], "\n"; + // Insert a document + $result = $collection->insertOne(['name' => 'Hinterland', 'brewery' => 'Coopers', 'abv' => 5.5]); + echo "Inserted with Object ID '{$result->getInsertedId()}'\n"; + // Query a document + $beer = $collection->findOne(['name' => 'Hinterland']); + echo "Beer: ", $beer['name'], " Brewery: ", $beer['brewery'], " ABV: ", $beer['abv'], "\n"; +} catch (Exception $e) { + printf("Caught exception: %s\n", $e->getMessage()); +} ?> ``` From 4d8cf33055232c1f079d7bb55ed76a670c1136e1 Mon Sep 17 00:00:00 2001 From: Pash10g Date: Mon, 1 Jul 2024 16:48:19 +0300 Subject: [PATCH 8/8] Update 07-07-01-Databases_MongoDB.md --- _posts/07-07-01-Databases_MongoDB.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/_posts/07-07-01-Databases_MongoDB.md b/_posts/07-07-01-Databases_MongoDB.md index a5ebc7948..e9310e23e 100644 --- a/_posts/07-07-01-Databases_MongoDB.md +++ b/_posts/07-07-01-Databases_MongoDB.md @@ -77,6 +77,13 @@ try { For more information, refer to the official [MongoDB PHP documentation][2]. +### MongoDB and PHP Frameworks + +MongoDB integrates seamlessly with popular PHP frameworks such as Laravel and Symfony. This compatibility allows developers to leverage MongoDB's powerful features while using the familiar structures and tools provided by these frameworks. For detailed instructions on how to integrate MongoDB with Laravel, please refer to the [Laravel MongoDB Documentation][3]. Similarly, for Symfony users, comprehensive guidance is available in the [Symfony MongoDB Documentation][4]. + + [1]: https://www.mongodb.com/ -[2]: https://www.mongodb.com/docs/drivers/php-drivers/ \ No newline at end of file +[2]: https://www.mongodb.com/docs/drivers/php-drivers/ +[3]: https://www.mongodb.com/docs/drivers/php/laravel-mongodb/ +[4]: https://www.mongodb.com/docs/drivers/php-frameworks/symfony/