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
An Eloquent model and Query builder with support for MongoDB, using the original Laravel API. *This library extends the original Laravel classes, so it uses exactly the same methods.*
5
+
An Eloquent model and Query builder with support for MongoDB, using the original Laravel API. _This library extends the original Laravel classes, so it uses exactly the same methods._
7
6
8
-
Table of contents
9
-
-----------------
10
-
*[Installation](#installation)
11
-
*[Upgrading](#upgrading)
12
-
*[Configuration](#configuration)
13
-
*[Eloquent](#eloquent)
14
-
*[Optional: Alias](#optional-alias)
15
-
*[Query Builder](#query-builder)
16
-
*[Schema](#schema)
17
-
*[Extensions](#extensions)
18
-
*[Troubleshooting](#troubleshooting)
19
-
*[Examples](#examples)
7
+
## Table of contents
20
8
21
-
Installation
22
-
------------
9
+
-[Installation](#installation)
10
+
-[Upgrading](#upgrading)
11
+
-[Configuration](#configuration)
12
+
-[Eloquent](#eloquent)
13
+
-[Optional: Alias](#optional-alias)
14
+
-[Query Builder](#query-builder)
15
+
-[Schema](#schema)
16
+
-[Extensions](#extensions)
17
+
-[Troubleshooting](#troubleshooting)
18
+
-[Examples](#examples)
23
19
24
-
Make sure you have the MongoDB PHP driver installed. You can find installation instructions at http://php.net/manual/en/mongodb.installation.php
20
+
## Installation
21
+
22
+
Make sure you have the MongoDB PHP driver installed. You can find installation instructions at <http://php.net/manual/en/mongodb.installation.php>
25
23
26
24
**WARNING**: The old mongo PHP driver is not supported anymore in versions >= 3.0.
@@ -108,17 +103,13 @@ Embedded relations now return an `Illuminate\Database\Eloquent\Collection` rathe
108
103
$books = $user->books()->sortBy('title');
109
104
```
110
105
111
-
Testing
112
-
-------
106
+
## Testing
113
107
114
108
To run the test for this package, run:
115
109
116
-
```
117
-
docker-compose up
118
-
```
110
+
docker-compose up
119
111
120
-
Configuration
121
-
-------------
112
+
## Configuration
122
113
123
114
Change your default database connection name in `config/database.php`:
124
115
@@ -168,10 +159,9 @@ Alternatively, you can use MongoDB connection string:
168
159
],
169
160
```
170
161
171
-
Please refer to MongoDB official docs for its URI format: https://docs.mongodb.com/manual/reference/connection-string/
162
+
Please refer to MongoDB official docs for its URI format: <https://docs.mongodb.com/manual/reference/connection-string/>
172
163
173
-
Eloquent
174
-
--------
164
+
## Eloquent
175
165
176
166
This package includes a MongoDB enabled Eloquent class that you can use to define models for corresponding collections.
177
167
@@ -205,7 +195,7 @@ class MyModel extends Eloquent {
205
195
}
206
196
```
207
197
208
-
Everything else (should) work just like the original Eloquent model. Read more about the Eloquent on http://laravel.com/docs/eloquent
198
+
Everything else (should) work just like the original Eloquent model. Read more about the Eloquent on <http://laravel.com/docs/eloquent>
209
199
210
200
### Optional: Alias
211
201
@@ -221,8 +211,7 @@ This will allow you to use the registered alias like:
221
211
class MyModel extends Moloquent {}
222
212
```
223
213
224
-
Query Builder
225
-
-------------
214
+
## Query Builder
226
215
227
216
The database driver plugs right into the original query builder. When using mongodb connections, you will be able to build fluent queries to perform database operations. For your convenience, there is a `collection` alias for `table` as well as some additional mongodb specific operators/operations.
228
217
@@ -238,10 +227,9 @@ If you did not change your default database connection, you will need to specify
All other (unsupported) operations are implemented as dummy pass-through methods, because MongoDB does not use a predefined schema. Read more about the schema builder on http://laravel.com/docs/schema
254
+
All other (unsupported) operations are implemented as dummy pass-through methods, because MongoDB does not use a predefined schema. Read more about the schema builder on <http://laravel.com/docs/schema>
If you want to use this library with [Sentry](https://cartalyst.com/manual/sentry), then check out https://github.com/jenssegers/Laravel-MongoDB-Sentry
321
+
If you want to use this library with [Sentry](https://cartalyst.com/manual/sentry), then check out <https://github.com/jenssegers/Laravel-MongoDB-Sentry>
335
322
336
323
### Sessions
337
324
338
-
The MongoDB session driver is available in a separate package, check out https://github.com/jenssegers/Laravel-MongoDB-Session
325
+
The MongoDB session driver is available in a separate package, check out <https://github.com/jenssegers/Laravel-MongoDB-Session>
*Aggregations are only available for MongoDB versions greater than 2.2.*
430
+
_Aggregations are only available for MongoDB versions greater than 2.2._
445
431
446
432
```php
447
433
$total = Order::count();
@@ -510,7 +496,7 @@ class User extends Eloquent {
510
496
}
511
497
```
512
498
513
-
For more information check http://laravel.com/docs/eloquent#soft-deleting
499
+
For more information check <http://laravel.com/docs/eloquent#soft-deleting>
514
500
515
501
### MongoDB specific operators
516
502
@@ -546,7 +532,7 @@ Selects documents where values match a specified regular expression.
546
532
User::where('name', 'regex', new \MongoDB\BSON\Regex("/.*doe/i"))->get();
547
533
```
548
534
549
-
**NOTE:** you can also use the Laravel regexp operations. These are a bit more flexible and will automatically convert your regular expression string to a MongoDB\BSON\Regex object.
535
+
**NOTE:** you can also use the Laravel regexp operations. These are a bit more flexible and will automatically convert your regular expression string to a MongoDB\\BSON\\Regex object.
Selects documents if a field is of the specified type. For more information check: http://docs.mongodb.org/manual/reference/operator/query/type/#op._S_type
549
+
Selects documents if a field is of the specified type. For more information check: <http://docs.mongodb.org/manual/reference/operator/query/type/#op._S_type>
Matches documents that satisfy a JavaScript expression. For more information check http://docs.mongodb.org/manual/reference/operator/query/where/#op._S_where
630
+
Matches documents that satisfy a JavaScript expression. For more information check <http://docs.mongodb.org/manual/reference/operator/query/where/#op._S_where>
*There is also support for upsert operations, check https://github.com/jenssegers/laravel-mongodb#mongodb-specific-operations*
660
+
_There is also support for upsert operations, check <https://github.com/jenssegers/laravel-mongodb#mongodb-specific-operations>_
676
661
677
662
**Deleting a model**
678
663
@@ -689,11 +674,11 @@ Or deleting a model by its key:
689
674
User::destroy('517c43667db388101e00000f');
690
675
```
691
676
692
-
For more information about model manipulation, check http://laravel.com/docs/eloquent#insert-update-delete
677
+
For more information about model manipulation, check <http://laravel.com/docs/eloquent#insert-update-delete>
693
678
694
679
### Dates
695
680
696
-
Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields, you will need to manually specify them as described here: http://laravel.com/docs/eloquent#date-mutators
681
+
Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields, you will need to manually specify them as described here: <http://laravel.com/docs/eloquent#date-mutators>
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`:
742
+
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`:
758
743
759
744
```php
760
745
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
@@ -769,8 +754,7 @@ class User extends Eloquent {
769
754
}
770
755
```
771
756
772
-
773
-
Other relations are not yet supported, but may be added in the future. Read more about these relations on http://laravel.com/docs/eloquent#relationships
757
+
Other relations are not yet supported, but may be added in the future. Read more about these relations on <http://laravel.com/docs/eloquent#relationships>
774
758
775
759
### EmbedsMany Relations
776
760
@@ -797,7 +781,7 @@ You can access the embedded models through the dynamic property:
797
781
$books = User::first()->books;
798
782
```
799
783
800
-
The inverse relation is auto*magically* available, you don't need to define this reverse relation.
784
+
The inverse relation is auto_magically_ available, you don't need to define this reverse relation.
801
785
802
786
```php
803
787
$user = $book->user;
@@ -849,7 +833,7 @@ Like other relations, embedsMany assumes the local key of the relationship based
849
833
return $this->embedsMany('Book', 'local_key');
850
834
```
851
835
852
-
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
836
+
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>
0 commit comments