From 09cd51dba82e3ad5f523d8274f4c96966ddf0438 Mon Sep 17 00:00:00 2001 From: henriquetroiano Date: Tue, 20 Dec 2022 10:47:08 -0300 Subject: [PATCH 1/7] create aggregate geonear instructions --- README.md | 240 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 135 insertions(+), 105 deletions(-) diff --git a/README.md b/README.md index 0c07e7288..defa43239 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -Laravel MongoDB -=============== +# Laravel MongoDB [![Latest Stable Version](http://img.shields.io/github/release/jenssegers/laravel-mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Total Downloads](http://img.shields.io/packagist/dm/jenssegers/mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) @@ -7,72 +6,72 @@ Laravel MongoDB [![codecov](https://codecov.io/gh/jenssegers/laravel-mongodb/branch/master/graph/badge.svg)](https://codecov.io/gh/jenssegers/laravel-mongodb/branch/master) [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/jenssegers) -This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. *This library extends the original Laravel classes, so it uses exactly the same methods.* - -- [Laravel MongoDB](#laravel-mongodb) - - [Installation](#installation) - - [Laravel version Compatibility](#laravel-version-compatibility) - - [Laravel](#laravel) - - [Lumen](#lumen) - - [Non-Laravel projects](#non-laravel-projects) - - [Testing](#testing) - - [Database Testing](#database-testing) - - [Configuration](#configuration) - - [Eloquent](#eloquent) - - [Extending the base model](#extending-the-base-model) - - [Extending the Authenticable base model](#extending-the-authenticable-base-model) - - [Soft Deletes](#soft-deletes) - - [Guarding attributes](#guarding-attributes) - - [Dates](#dates) - - [Basic Usage](#basic-usage) - - [MongoDB-specific operators](#mongodb-specific-operators) - - [MongoDB-specific Geo operations](#mongodb-specific-geo-operations) - - [Inserts, updates and deletes](#inserts-updates-and-deletes) - - [MongoDB specific operations](#mongodb-specific-operations) - - [Relationships](#relationships) - - [Basic Usage](#basic-usage-1) - - [belongsToMany and pivots](#belongstomany-and-pivots) - - [EmbedsMany Relationship](#embedsmany-relationship) - - [EmbedsOne Relationship](#embedsone-relationship) - - [Query Builder](#query-builder) - - [Basic Usage](#basic-usage-2) - - [Available operations](#available-operations) - - [Transactions](#transactions) - - [Schema](#schema) - - [Basic Usage](#basic-usage-3) - - [Geospatial indexes](#geospatial-indexes) - - [Extending](#extending) - - [Cross-Database Relationships](#cross-database-relationships) - - [Authentication](#authentication) - - [Queues](#queues) - - [Laravel specific](#laravel-specific) - - [Lumen specific](#lumen-specific) - - [Upgrading](#upgrading) - - [Upgrading from version 2 to 3](#upgrading-from-version-2-to-3) - - [Security contact information](#security-contact-information) - -Installation ------------- +This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. _This library extends the original Laravel classes, so it uses exactly the same methods._ + +- [Laravel MongoDB](#laravel-mongodb) + - [Installation](#installation) + - [Laravel version Compatibility](#laravel-version-compatibility) + - [Laravel](#laravel) + - [Lumen](#lumen) + - [Non-Laravel projects](#non-laravel-projects) + - [Testing](#testing) + - [Database Testing](#database-testing) + - [Configuration](#configuration) + - [Eloquent](#eloquent) + - [Extending the base model](#extending-the-base-model) + - [Extending the Authenticable base model](#extending-the-authenticable-base-model) + - [Soft Deletes](#soft-deletes) + - [Guarding attributes](#guarding-attributes) + - [Dates](#dates) + - [Basic Usage](#basic-usage) + - [MongoDB-specific operators](#mongodb-specific-operators) + - [MongoDB-specific Geo operations](#mongodb-specific-geo-operations) + - [Inserts, updates and deletes](#inserts-updates-and-deletes) + - [MongoDB specific operations](#mongodb-specific-operations) + - [Relationships](#relationships) + - [Basic Usage](#basic-usage-1) + - [belongsToMany and pivots](#belongstomany-and-pivots) + - [EmbedsMany Relationship](#embedsmany-relationship) + - [EmbedsOne Relationship](#embedsone-relationship) + - [Query Builder](#query-builder) + - [Basic Usage](#basic-usage-2) + - [Available operations](#available-operations) + - [Transactions](#transactions) + - [Schema](#schema) + - [Basic Usage](#basic-usage-3) + - [Geospatial indexes](#geospatial-indexes) + - [Extending](#extending) + - [Cross-Database Relationships](#cross-database-relationships) + - [Authentication](#authentication) + - [Queues](#queues) + - [Laravel specific](#laravel-specific) + - [Lumen specific](#lumen-specific) + - [Upgrading](#upgrading) + - [Upgrading from version 2 to 3](#upgrading-from-version-2-to-3) + - [Security contact information](#security-contact-information) + +## Installation + Make sure you have the MongoDB PHP driver installed. You can find installation instructions at http://php.net/manual/en/mongodb.installation.php ### Laravel version Compatibility - Laravel | Package | Maintained -:---------|:---------------|:---------- - 9.x | 3.9.x | :white_check_mark: - 8.x | 3.8.x | :white_check_mark: - 7.x | 3.7.x | :x: - 6.x | 3.6.x | :white_check_mark: - 5.8.x | 3.5.x | :x: - 5.7.x | 3.4.x | :x: - 5.6.x | 3.4.x | :x: - 5.5.x | 3.3.x | :x: - 5.4.x | 3.2.x | :x: - 5.3.x | 3.1.x or 3.2.x | :x: - 5.2.x | 2.3.x or 3.0.x | :x: - 5.1.x | 2.2.x or 3.0.x | :x: - 5.0.x | 2.1.x | :x: - 4.2.x | 2.0.x | :x: +| Laravel | Package | Maintained | +| :------ | :------------- | :----------------- | +| 9.x | 3.9.x | :white_check_mark: | +| 8.x | 3.8.x | :white_check_mark: | +| 7.x | 3.7.x | :x: | +| 6.x | 3.6.x | :white_check_mark: | +| 5.8.x | 3.5.x | :x: | +| 5.7.x | 3.4.x | :x: | +| 5.6.x | 3.4.x | :x: | +| 5.5.x | 3.3.x | :x: | +| 5.4.x | 3.2.x | :x: | +| 5.3.x | 3.1.x or 3.2.x | :x: | +| 5.2.x | 2.3.x or 3.0.x | :x: | +| 5.1.x | 2.2.x or 3.0.x | :x: | +| 5.0.x | 2.1.x | :x: | +| 4.2.x | 2.0.x | :x: | Install the package via Composer: @@ -114,8 +113,7 @@ $capsule->getDatabaseManager()->extend('mongodb', function($config, $name) { }); ``` -Testing -------- +## Testing To run the test for this package, run: @@ -123,8 +121,7 @@ To run the test for this package, run: docker-compose up ``` -Database Testing -------- +## Database Testing To reset the database after each test, add: @@ -139,11 +136,11 @@ use DatabaseMigrations; ``` Keep in mind that these traits are not yet supported: -- `use Database Transactions;` -- `use RefreshDatabase;` -Configuration -------------- +- `use Database Transactions;` +- `use RefreshDatabase;` + +## Configuration To configure a new MongoDB connection, add a new connection entry to `config/database.php`: @@ -175,10 +172,10 @@ Instead of using a connection string, you can also use the `host` and `port` con The `options` key in the connection configuration corresponds to the [`uriOptions` parameter](https://www.php.net/manual/en/mongodb-driver-manager.construct.php#mongodb-driver-manager.construct-urioptions). -Eloquent --------- +## Eloquent ### Extending the base model + This package includes a MongoDB enabled Eloquent class that you can use to define models for corresponding collections. ```php @@ -229,6 +226,7 @@ class Book extends Model ``` ### Extending the Authenticatable base model + This package includes a MongoDB Authenticatable Eloquent class `Jenssegers\Mongodb\Auth\User` that you can use to replace the default Authenticatable class `Illuminate\Foundation\Auth\User` for your `User` model. ```php @@ -354,8 +352,8 @@ $users = User::whereNull('age')->get(); ```php $users = User::whereDate('birthday', '2021-5-12')->get(); ``` -The usage is the same as `whereMonth` / `whereDay` / `whereYear` / `whereTime` +The usage is the same as `whereMonth` / `whereDay` / `whereYear` / `whereTime` **Advanced wheres** @@ -584,6 +582,34 @@ $bars = Bar::where('location', 'geoIntersects', [ ], ])->get(); ``` + +**GeoNear** + +You are able to make a `geoNear` query on mongoDB. +You don't need to specify the automatic fields on the model. +The returned instance is a collection. So you're able to make the [Collection](https://laravel.com/docs/9.x/collections) operations. +Just make sure that your model has a `location` field, and a [2ndSphereIndex](https://www.mongodb.com/docs/manual/core/2dsphere) +The data in the `location` field must be saved as [GeoJSON](https://www.mongodb.com/docs/manual/reference/geojson/) +The `location` points must be saved as [WGS84](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-WGS84) reference system for geometry calculation. That means, basically, you need to save longitude and latitude, in that order specifically. + +``` +Bar::find("63a0cd574d08564f330ceae2")->update(['location' => ['type' => 'Point','coordinates' => [-0.1367563, 51.5100913]]]); +$bars = Bar::raw(function ($collection) { + return $collection->aggregate([ + [ + '$geoNear' => [ + "near" => [ "type" => "Point", "coordinates" => [-0.132239, 51.511874] ], + "distanceField" => "dist.calculated", + "minDistance" => 0, + "maxDistance" => 6000, + "includeLocs" => "dist.location", + "spherical" => true, + ] + ] + ]); +}); +``` + ### Inserts, updates and deletes Inserting, updating and deleting records works just like the original Eloquent. Please check [Laravel Docs' Eloquent section](https://laravel.com/docs/6.x/eloquent). @@ -734,20 +760,21 @@ DB::collection('users') $user->unset('note'); ``` -Relationships -------------- +## Relationships ### Basic Usage The only available relationships are: - - hasOne - - hasMany - - belongsTo - - belongsToMany + +- hasOne +- hasMany +- belongsTo +- belongsToMany The MongoDB-specific relationships are: - - embedsOne - - embedsMany + +- embedsOne +- embedsMany Here is a small example: @@ -779,7 +806,7 @@ class Item extends Model ### belongsToMany and pivots -The belongsToMany relation will not use a pivot "table" but will push id's to a __related_ids__ attribute instead. This makes the second parameter for the belongsToMany method useless. +The belongsToMany relation will not use a pivot "table" but will push id's to a **related_ids** attribute instead. This makes the second parameter for the belongsToMany method useless. If you want to define custom keys for your relation, set it to `null`: @@ -889,7 +916,6 @@ class User extends Model Embedded relations will return a Collection of embedded items instead of a query builder. Check out the available operations here: https://laravel.com/docs/master/collections - ### EmbedsOne Relationship The embedsOne relation is similar to the embedsMany relation, but only embeds a single model. @@ -943,8 +969,7 @@ $newAuthor = new Author(['name' => 'Jane Doe']); $book->author()->save($newAuthor); ``` -Query Builder -------------- +## Query Builder ### Basic Usage @@ -954,7 +979,6 @@ When using MongoDB connections, you will be able to build fluent queries to perf For your convenience, there is a `collection` alias for `table` as well as some additional MongoDB specific operators/operations. - ```php $books = DB::collection('books')->get(); @@ -967,10 +991,11 @@ $hungerGames = If you are familiar with [Eloquent Queries](http://laravel.com/docs/queries), there is the same functionality. ### Available operations + To see the available operations, check the [Eloquent](#eloquent) section. -Transactions ------------- +## Transactions + Transactions require MongoDB version ^4.0 as well as deployment of replica set or sharded clusters. You can find more information [in the MongoDB docs](https://docs.mongodb.com/manual/core/transactions/) ### Basic Usage @@ -995,6 +1020,7 @@ DB::commit(); ``` To abort a transaction, call the `rollBack` method at any point during the transaction: + ```php DB::beginTransaction(); User::create(['name' => 'john', 'age' => 19, 'title' => 'admin', 'email' => 'john@example.com']); @@ -1004,6 +1030,7 @@ DB::rollBack(); ``` **NOTE:** Transactions in MongoDB cannot be nested. DB::beginTransaction() function will start new transactions in a new created or existing session and will raise the RuntimeException when transactions already exist. See more in MongoDB official docs [Transactions and Sessions](https://www.mongodb.com/docs/manual/core/transactions/#transactions-and-sessions) + ```php DB::beginTransaction(); User::create(['name' => 'john', 'age' => 20, 'title' => 'admin']); @@ -1015,8 +1042,8 @@ DB::commit(); DB::rollBack(); ``` -Schema ------- +## Schema + The database driver also has (limited) schema builder support. You can easily manipulate collections and set indexes. ### Basic Usage @@ -1046,17 +1073,19 @@ Schema::create('users', function ($collection) { ``` Inherited operations: -- create and drop -- collection -- hasCollection -- index and dropIndex (compound indexes supported as well) -- unique + +- create and drop +- collection +- hasCollection +- index and dropIndex (compound indexes supported as well) +- unique MongoDB specific operations: -- background -- sparse -- expire -- geospatial + +- background +- sparse +- expire +- geospatial All other (unsupported) operations are implemented as dummy pass-through methods because MongoDB does not use a predefined schema. @@ -1082,8 +1111,7 @@ Schema::create('bars', function ($collection) { }); ``` -Extending ---------- +## Extending ### Cross-Database Relationships @@ -1112,6 +1140,7 @@ class User extends Model } } ``` + Within your MongoDB model, you should define the relationship: ```php @@ -1129,6 +1158,7 @@ class Message extends Model ``` ### Authentication + If you want to use Laravel's native Auth functionality, register this included service provider: ```php @@ -1140,6 +1170,7 @@ This service provider will slightly modify the internal DatabaseReminderReposito If you don't use password reminders, you don't have to register this service provider and everything else should work just fine. ### Queues + If you want to use MongoDB as your database backend, change the driver in `config/queue.php`: ```php @@ -1184,8 +1215,7 @@ $app->make('queue'); $app->register(Jenssegers\Mongodb\MongodbQueueServiceProvider::class); ``` -Upgrading ---------- +## Upgrading #### Upgrading from version 2 to 3 From 21c48809281e2423305e6cfcc6d72c0d3938341f Mon Sep 17 00:00:00 2001 From: henriquetroiano Date: Tue, 20 Dec 2022 10:52:06 -0300 Subject: [PATCH 2/7] create aggregate geonear instructions --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index defa43239..9eb327813 100644 --- a/README.md +++ b/README.md @@ -593,7 +593,17 @@ The data in the `location` field must be saved as [GeoJSON](https://www.mongodb. The `location` points must be saved as [WGS84](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-WGS84) reference system for geometry calculation. That means, basically, you need to save longitude and latitude, in that order specifically. ``` -Bar::find("63a0cd574d08564f330ceae2")->update(['location' => ['type' => 'Point','coordinates' => [-0.1367563, 51.5100913]]]); +Bar::find("63a0cd574d08564f330ceae2")->update( + [ + 'location' => [ + 'type' => 'Point', + 'coordinates' => [ + -0.1367563, + 51.5100913 + ] + ] + ] +); $bars = Bar::raw(function ($collection) { return $collection->aggregate([ [ From 8aac21daac2c8ea8d5c9bec7fdef0da297248c8e Mon Sep 17 00:00:00 2001 From: henriquetroiano Date: Tue, 20 Dec 2022 10:53:11 -0300 Subject: [PATCH 3/7] create aggregate geonear instructions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9eb327813..6ae29c747 100644 --- a/README.md +++ b/README.md @@ -588,8 +588,8 @@ $bars = Bar::where('location', 'geoIntersects', [ You are able to make a `geoNear` query on mongoDB. You don't need to specify the automatic fields on the model. The returned instance is a collection. So you're able to make the [Collection](https://laravel.com/docs/9.x/collections) operations. -Just make sure that your model has a `location` field, and a [2ndSphereIndex](https://www.mongodb.com/docs/manual/core/2dsphere) -The data in the `location` field must be saved as [GeoJSON](https://www.mongodb.com/docs/manual/reference/geojson/) +Just make sure that your model has a `location` field, and a [2ndSphereIndex](https://www.mongodb.com/docs/manual/core/2dsphere). +The data in the `location` field must be saved as [GeoJSON](https://www.mongodb.com/docs/manual/reference/geojson/). The `location` points must be saved as [WGS84](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-WGS84) reference system for geometry calculation. That means, basically, you need to save longitude and latitude, in that order specifically. ``` From 48583618cade6968ab7ec32b21a309dd3ff5d819 Mon Sep 17 00:00:00 2001 From: henriquetroiano Date: Tue, 20 Dec 2022 10:54:08 -0300 Subject: [PATCH 4/7] create aggregate geonear instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ae29c747..4f7b3984b 100644 --- a/README.md +++ b/README.md @@ -590,7 +590,7 @@ You don't need to specify the automatic fields on the model. The returned instance is a collection. So you're able to make the [Collection](https://laravel.com/docs/9.x/collections) operations. Just make sure that your model has a `location` field, and a [2ndSphereIndex](https://www.mongodb.com/docs/manual/core/2dsphere). The data in the `location` field must be saved as [GeoJSON](https://www.mongodb.com/docs/manual/reference/geojson/). -The `location` points must be saved as [WGS84](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-WGS84) reference system for geometry calculation. That means, basically, you need to save longitude and latitude, in that order specifically. +The `location` points must be saved as [WGS84](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-WGS84) reference system for geometry calculation. That means, basically, you need to save longitude and latitude, in that order specifically, and to find near with calculated distance, you `need to do the same way`. ``` Bar::find("63a0cd574d08564f330ceae2")->update( From b70a4d53ef1f4894ccddc701d6bddf42e684610f Mon Sep 17 00:00:00 2001 From: henriquetroiano Date: Tue, 20 Dec 2022 10:54:41 -0300 Subject: [PATCH 5/7] create aggregate geonear instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f7b3984b..d52a8be1e 100644 --- a/README.md +++ b/README.md @@ -590,7 +590,7 @@ You don't need to specify the automatic fields on the model. The returned instance is a collection. So you're able to make the [Collection](https://laravel.com/docs/9.x/collections) operations. Just make sure that your model has a `location` field, and a [2ndSphereIndex](https://www.mongodb.com/docs/manual/core/2dsphere). The data in the `location` field must be saved as [GeoJSON](https://www.mongodb.com/docs/manual/reference/geojson/). -The `location` points must be saved as [WGS84](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-WGS84) reference system for geometry calculation. That means, basically, you need to save longitude and latitude, in that order specifically, and to find near with calculated distance, you `need to do the same way`. +The `location` points must be saved as [WGS84](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-WGS84) reference system for geometry calculation. That means, basically, you need to save `longitude and latitude`, in that order specifically, and to find near with calculated distance, you `need to do the same way`. ``` Bar::find("63a0cd574d08564f330ceae2")->update( From d365697fca54d770b9c74e8ef87bc9d21d684a53 Mon Sep 17 00:00:00 2001 From: divine <48183131+divine@users.noreply.github.com> Date: Mon, 16 Jan 2023 02:14:04 +0300 Subject: [PATCH 6/7] chore: revert back readme changes --- README.md | 122 +++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index d52a8be1e..772dc57dc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Laravel MongoDB +Laravel MongoDB +=============== [![Latest Stable Version](http://img.shields.io/github/release/jenssegers/laravel-mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Total Downloads](http://img.shields.io/packagist/dm/jenssegers/mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) @@ -6,49 +7,48 @@ [![codecov](https://codecov.io/gh/jenssegers/laravel-mongodb/branch/master/graph/badge.svg)](https://codecov.io/gh/jenssegers/laravel-mongodb/branch/master) [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/jenssegers) -This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. _This library extends the original Laravel classes, so it uses exactly the same methods._ - -- [Laravel MongoDB](#laravel-mongodb) - - [Installation](#installation) - - [Laravel version Compatibility](#laravel-version-compatibility) - - [Laravel](#laravel) - - [Lumen](#lumen) - - [Non-Laravel projects](#non-laravel-projects) - - [Testing](#testing) - - [Database Testing](#database-testing) - - [Configuration](#configuration) - - [Eloquent](#eloquent) - - [Extending the base model](#extending-the-base-model) - - [Extending the Authenticable base model](#extending-the-authenticable-base-model) - - [Soft Deletes](#soft-deletes) - - [Guarding attributes](#guarding-attributes) - - [Dates](#dates) - - [Basic Usage](#basic-usage) - - [MongoDB-specific operators](#mongodb-specific-operators) - - [MongoDB-specific Geo operations](#mongodb-specific-geo-operations) - - [Inserts, updates and deletes](#inserts-updates-and-deletes) - - [MongoDB specific operations](#mongodb-specific-operations) - - [Relationships](#relationships) - - [Basic Usage](#basic-usage-1) - - [belongsToMany and pivots](#belongstomany-and-pivots) - - [EmbedsMany Relationship](#embedsmany-relationship) - - [EmbedsOne Relationship](#embedsone-relationship) - - [Query Builder](#query-builder) - - [Basic Usage](#basic-usage-2) - - [Available operations](#available-operations) - - [Transactions](#transactions) - - [Schema](#schema) - - [Basic Usage](#basic-usage-3) - - [Geospatial indexes](#geospatial-indexes) - - [Extending](#extending) - - [Cross-Database Relationships](#cross-database-relationships) - - [Authentication](#authentication) - - [Queues](#queues) - - [Laravel specific](#laravel-specific) - - [Lumen specific](#lumen-specific) - - [Upgrading](#upgrading) - - [Upgrading from version 2 to 3](#upgrading-from-version-2-to-3) - - [Security contact information](#security-contact-information) +This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. *This library extends the original Laravel classes, so it uses exactly the same methods.* +- [Laravel MongoDB](#laravel-mongodb) + - [Installation](#installation) + - [Laravel version Compatibility](#laravel-version-compatibility) + - [Laravel](#laravel) + - [Lumen](#lumen) + - [Non-Laravel projects](#non-laravel-projects) + - [Testing](#testing) + - [Database Testing](#database-testing) + - [Configuration](#configuration) + - [Eloquent](#eloquent) + - [Extending the base model](#extending-the-base-model) + - [Extending the Authenticable base model](#extending-the-authenticable-base-model) + - [Soft Deletes](#soft-deletes) + - [Guarding attributes](#guarding-attributes) + - [Dates](#dates) + - [Basic Usage](#basic-usage) + - [MongoDB-specific operators](#mongodb-specific-operators) + - [MongoDB-specific Geo operations](#mongodb-specific-geo-operations) + - [Inserts, updates and deletes](#inserts-updates-and-deletes) + - [MongoDB specific operations](#mongodb-specific-operations) + - [Relationships](#relationships) + - [Basic Usage](#basic-usage-1) + - [belongsToMany and pivots](#belongstomany-and-pivots) + - [EmbedsMany Relationship](#embedsmany-relationship) + - [EmbedsOne Relationship](#embedsone-relationship) + - [Query Builder](#query-builder) + - [Basic Usage](#basic-usage-2) + - [Available operations](#available-operations) + - [Transactions](#transactions) + - [Schema](#schema) + - [Basic Usage](#basic-usage-3) + - [Geospatial indexes](#geospatial-indexes) + - [Extending](#extending) + - [Cross-Database Relationships](#cross-database-relationships) + - [Authentication](#authentication) + - [Queues](#queues) + - [Laravel specific](#laravel-specific) + - [Lumen specific](#lumen-specific) + - [Upgrading](#upgrading) + - [Upgrading from version 2 to 3](#upgrading-from-version-2-to-3) + - [Security contact information](#security-contact-information) ## Installation @@ -61,7 +61,7 @@ Make sure you have the MongoDB PHP driver installed. You can find installation i | 9.x | 3.9.x | :white_check_mark: | | 8.x | 3.8.x | :white_check_mark: | | 7.x | 3.7.x | :x: | -| 6.x | 3.6.x | :white_check_mark: | +| 6.x | 3.6.x | :x: | | 5.8.x | 3.5.x | :x: | | 5.7.x | 3.4.x | :x: | | 5.6.x | 3.4.x | :x: | @@ -113,7 +113,8 @@ $capsule->getDatabaseManager()->extend('mongodb', function($config, $name) { }); ``` -## Testing +Testing +------- To run the test for this package, run: @@ -121,7 +122,8 @@ To run the test for this package, run: docker-compose up ``` -## Database Testing +Database Testing +------- To reset the database after each test, add: @@ -140,7 +142,8 @@ Keep in mind that these traits are not yet supported: - `use Database Transactions;` - `use RefreshDatabase;` -## Configuration +Configuration +------------- To configure a new MongoDB connection, add a new connection entry to `config/database.php`: @@ -172,7 +175,8 @@ Instead of using a connection string, you can also use the `host` and `port` con The `options` key in the connection configuration corresponds to the [`uriOptions` parameter](https://www.php.net/manual/en/mongodb-driver-manager.construct.php#mongodb-driver-manager.construct-urioptions). -## Eloquent +Eloquent +-------- ### Extending the base model @@ -770,7 +774,8 @@ DB::collection('users') $user->unset('note'); ``` -## Relationships +Relationships +------------- ### Basic Usage @@ -816,7 +821,7 @@ class Item extends Model ### belongsToMany and pivots -The belongsToMany relation will not use a pivot "table" but will push id's to a **related_ids** attribute instead. This makes the second parameter for the belongsToMany method useless. +The belongsToMany relation will not use a pivot "table" but will push id's to a __related_ids__ attribute instead. This makes the second parameter for the belongsToMany method useless. If you want to define custom keys for your relation, set it to `null`: @@ -979,7 +984,8 @@ $newAuthor = new Author(['name' => 'Jane Doe']); $book->author()->save($newAuthor); ``` -## Query Builder +Query Builder +------------- ### Basic Usage @@ -1004,7 +1010,8 @@ If you are familiar with [Eloquent Queries](http://laravel.com/docs/queries), th To see the available operations, check the [Eloquent](#eloquent) section. -## Transactions +Transactions +------------ Transactions require MongoDB version ^4.0 as well as deployment of replica set or sharded clusters. You can find more information [in the MongoDB docs](https://docs.mongodb.com/manual/core/transactions/) @@ -1052,7 +1059,8 @@ DB::commit(); DB::rollBack(); ``` -## Schema +Schema +------ The database driver also has (limited) schema builder support. You can easily manipulate collections and set indexes. @@ -1121,7 +1129,8 @@ Schema::create('bars', function ($collection) { }); ``` -## Extending +Extending +--------- ### Cross-Database Relationships @@ -1225,7 +1234,8 @@ $app->make('queue'); $app->register(Jenssegers\Mongodb\MongodbQueueServiceProvider::class); ``` -## Upgrading +Upgrading +--------- #### Upgrading from version 2 to 3 From efd98f3fe8c4031a0abde3a1b4f0b45c9735b6b8 Mon Sep 17 00:00:00 2001 From: divine <48183131+divine@users.noreply.github.com> Date: Mon, 16 Jan 2023 02:17:11 +0300 Subject: [PATCH 7/7] chore: minor readme change --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 772dc57dc..f201b2514 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ Laravel MongoDB [![codecov](https://codecov.io/gh/jenssegers/laravel-mongodb/branch/master/graph/badge.svg)](https://codecov.io/gh/jenssegers/laravel-mongodb/branch/master) [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/jenssegers) -This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. *This library extends the original Laravel classes, so it uses exactly the same methods.* +This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. *This library extends the original Laravel classes, so it uses exactly the same methods.* + - [Laravel MongoDB](#laravel-mongodb) - [Installation](#installation) - [Laravel version Compatibility](#laravel-version-compatibility) @@ -50,7 +51,8 @@ This package adds functionalities to the Eloquent model and Query builder for Mo - [Upgrading from version 2 to 3](#upgrading-from-version-2-to-3) - [Security contact information](#security-contact-information) -## Installation +Installation +------------ Make sure you have the MongoDB PHP driver installed. You can find installation instructions at http://php.net/manual/en/mongodb.installation.php