You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+128-76
Original file line number
Diff line number
Diff line change
@@ -10,69 +10,70 @@ Laravel MongoDB
10
10
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.*
11
11
12
12
-[Laravel MongoDB](#laravel-mongodb)
13
-
-[Installation](#installation)
14
-
-[Laravel version Compatibility](#laravel-version-compatibility)
15
-
-[Laravel](#laravel)
16
-
-[Lumen](#lumen)
17
-
-[Non-Laravel projects](#non-laravel-projects)
18
-
-[Testing](#testing)
19
-
-[Database Testing](#database-testing)
20
-
-[Configuration](#configuration)
21
-
-[Eloquent](#eloquent)
22
-
-[Extending the base model](#extending-the-base-model)
23
-
-[Extending the Authenticable base model](#extending-the-authenticable-base-model)
Make sure you have the MongoDB PHP driver installed. You can find installation instructions at http://php.net/manual/en/mongodb.installation.php
57
58
58
59
### Laravel version Compatibility
59
60
60
-
Laravel | Package | Maintained
61
-
:---------|:---------------|:----------
62
-
9.x | 3.9.x | :white_check_mark:
63
-
8.x | 3.8.x | :white_check_mark:
64
-
7.x | 3.7.x | :x:
65
-
6.x | 3.6.x | :white_check_mark:
66
-
5.8.x | 3.5.x | :x:
67
-
5.7.x | 3.4.x | :x:
68
-
5.6.x | 3.4.x | :x:
69
-
5.5.x | 3.3.x | :x:
70
-
5.4.x | 3.2.x | :x:
71
-
5.3.x | 3.1.x or 3.2.x | :x:
72
-
5.2.x | 2.3.x or 3.0.x | :x:
73
-
5.1.x | 2.2.x or 3.0.x | :x:
74
-
5.0.x | 2.1.x | :x:
75
-
4.2.x | 2.0.x | :x:
61
+
| Laravel | Package | Maintained|
62
+
|:------| :-------------| :----------------- |
63
+
| 9.x | 3.9.x |:white_check_mark:|
64
+
| 8.x | 3.8.x |:white_check_mark:|
65
+
| 7.x | 3.7.x |:x:|
66
+
| 6.x | 3.6.x |:x:|
67
+
| 5.8.x | 3.5.x |:x:|
68
+
| 5.7.x | 3.4.x |:x:|
69
+
| 5.6.x | 3.4.x |:x:|
70
+
| 5.5.x | 3.3.x |:x:|
71
+
| 5.4.x | 3.2.x |:x:|
72
+
| 5.3.x | 3.1.x or 3.2.x |:x:|
73
+
| 5.2.x | 2.3.x or 3.0.x |:x:|
74
+
| 5.1.x | 2.2.x or 3.0.x |:x:|
75
+
| 5.0.x | 2.1.x |:x:|
76
+
| 4.2.x | 2.0.x |:x:|
76
77
77
78
Install the package via Composer:
78
79
@@ -139,8 +140,9 @@ use DatabaseMigrations;
139
140
```
140
141
141
142
Keep in mind that these traits are not yet supported:
142
-
-`use Database Transactions;`
143
-
-`use RefreshDatabase;`
143
+
144
+
-`use Database Transactions;`
145
+
-`use RefreshDatabase;`
144
146
145
147
Configuration
146
148
-------------
@@ -179,6 +181,7 @@ Eloquent
179
181
--------
180
182
181
183
### Extending the base model
184
+
182
185
This package includes a MongoDB enabled Eloquent class that you can use to define models for corresponding collections.
183
186
184
187
```php
@@ -229,6 +232,7 @@ class Book extends Model
229
232
```
230
233
231
234
### Extending the Authenticatable base model
235
+
232
236
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.
You are able to make a `geoNear` query on mongoDB.
595
+
You don't need to specify the automatic fields on the model.
596
+
The returned instance is a collection. So you're able to make the [Collection](https://laravel.com/docs/9.x/collections) operations.
597
+
Just make sure that your model has a `location` field, and a [2ndSphereIndex](https://www.mongodb.com/docs/manual/core/2dsphere).
598
+
The data in the `location` field must be saved as [GeoJSON](https://www.mongodb.com/docs/manual/reference/geojson/).
599
+
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`.
Inserting, updating and deleting records works just like the original Eloquent. Please check [Laravel Docs' Eloquent section](https://laravel.com/docs/6.x/eloquent).
@@ -740,14 +782,16 @@ Relationships
740
782
### Basic Usage
741
783
742
784
The only available relationships are:
743
-
- hasOne
744
-
- hasMany
745
-
- belongsTo
746
-
- belongsToMany
785
+
786
+
- hasOne
787
+
- hasMany
788
+
- belongsTo
789
+
- belongsToMany
747
790
748
791
The MongoDB-specific relationships are:
749
-
- embedsOne
750
-
- embedsMany
792
+
793
+
- embedsOne
794
+
- embedsMany
751
795
752
796
Here is a small example:
753
797
@@ -889,7 +933,6 @@ class User extends Model
889
933
890
934
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
891
935
892
-
893
936
### EmbedsOne Relationship
894
937
895
938
The embedsOne relation is similar to the embedsMany relation, but only embeds a single model.
@@ -954,7 +997,6 @@ When using MongoDB connections, you will be able to build fluent queries to perf
954
997
955
998
For your convenience, there is a `collection` alias for `table` as well as some additional MongoDB specific operators/operations.
956
999
957
-
958
1000
```php
959
1001
$books = DB::collection('books')->get();
960
1002
@@ -967,10 +1009,12 @@ $hungerGames =
967
1009
If you are familiar with [Eloquent Queries](http://laravel.com/docs/queries), there is the same functionality.
968
1010
969
1011
### Available operations
1012
+
970
1013
To see the available operations, check the [Eloquent](#eloquent) section.
971
1014
972
1015
Transactions
973
1016
------------
1017
+
974
1018
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/)
975
1019
976
1020
### Basic Usage
@@ -995,6 +1039,7 @@ DB::commit();
995
1039
```
996
1040
997
1041
To abort a transaction, call the `rollBack` method at any point during the transaction:
**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)
0 commit comments