Skip to content

Commit 0b810e7

Browse files
committed
Use version 3.0.2 as master and add morphs to blueprint
1 parent 7445ea6 commit 0b810e7

27 files changed

+1071
-1524
lines changed

README.md

+21-161
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ composer require jenssegers/mongodb
3939
5.0.x | 2.1.x
4040
5.1.x | 2.2.x or 3.0.x
4141
5.2.x | 2.3.x or 3.0.x
42-
5.3.x | 3.1.x or 3.2.x
43-
5.4.x | 3.2.x
44-
5.5.x | 3.3.x
45-
5.6.x | 3.4.x
4642

4743
And add the service provider in `config/app.php`:
4844

@@ -53,7 +49,7 @@ Jenssegers\Mongodb\MongodbServiceProvider::class,
5349
For usage with [Lumen](http://lumen.laravel.com), add the service provider in `bootstrap/app.php`. In this file, you will also need to enable Eloquent. You must however ensure that your call to `$app->withEloquent();` is **below** where you have registered the `MongodbServiceProvider`:
5450

5551
```php
56-
$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class);
52+
$app->register('Jenssegers\Mongodb\MongodbServiceProvider');
5753

5854
$app->withEloquent();
5955
```
@@ -104,19 +100,10 @@ Embedded relations now return an `Illuminate\Database\Eloquent\Collection` rathe
104100
$books = $user->books()->sortBy('title');
105101
```
106102

107-
Testing
108-
-------
109-
110-
To run the test for this package, run:
111-
112-
```
113-
docker-compose up
114-
```
115-
116103
Configuration
117104
-------------
118105

119-
Change your default database connection name in `config/database.php`:
106+
Change your default database connection name in `app/config/database.php`:
120107

121108
```php
122109
'default' => env('DB_CONNECTION', 'mongodb'),
@@ -129,11 +116,11 @@ And add a new mongodb connection:
129116
'driver' => 'mongodb',
130117
'host' => env('DB_HOST', 'localhost'),
131118
'port' => env('DB_PORT', 27017),
132-
'database' => env('DB_DATABASE'),
133-
'username' => env('DB_USERNAME'),
134-
'password' => env('DB_PASSWORD'),
135-
'options' => [
136-
'database' => 'admin' // sets the authentication database required by mongo 3
119+
'database' => env('DB_DATABASE', ''),
120+
'username' => env('DB_USERNAME', ''),
121+
'password' => env('DB_PASSWORD', ''),
122+
'options' => [
123+
'db' => 'admin' // sets the authentication database required by mongo 3
137124
]
138125
],
139126
```
@@ -145,27 +132,13 @@ You can connect to multiple servers or replica sets with the following configura
145132
'driver' => 'mongodb',
146133
'host' => ['server1', 'server2'],
147134
'port' => env('DB_PORT', 27017),
148-
'database' => env('DB_DATABASE'),
149-
'username' => env('DB_USERNAME'),
150-
'password' => env('DB_PASSWORD'),
151-
'options' => [
152-
'replicaSet' => 'replicaSetName'
153-
]
135+
'database' => env('DB_DATABASE', ''),
136+
'username' => env('DB_USERNAME', ''),
137+
'password' => env('DB_PASSWORD', ''),
138+
'options' => ['replicaSet' => 'replicaSetName']
154139
],
155140
```
156141

157-
Alternatively, you can use MongoDB connection string:
158-
159-
```php
160-
'mongodb' => [
161-
'driver' => 'mongodb',
162-
'dsn' => env('DB_DSN'),
163-
'database' => env('DB_DATABASE'),
164-
],
165-
```
166-
167-
Please refer to MongoDB official docs for its URI format: https://docs.mongodb.com/manual/reference/connection-string/
168-
169142
Eloquent
170143
--------
171144

@@ -177,7 +150,7 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
177150
class User extends Eloquent {}
178151
```
179152

180-
Note that we did not tell Eloquent which collection to use for the `User` model. Just like the original Eloquent, the lower-case, plural name of the class will be used as the collection name unless another name is explicitly specified. You may specify a custom collection (alias for table) by defining a `collection` property on your model:
153+
Note that we did not tell Eloquent which collection to use for the `User` model. Just like the original Eloquent, the lower-case, plural name of the class will be used as the table name unless another name is explicitly specified. You may specify a custom collection (alias for table) by defining a `collection` property on your model:
181154

182155
```php
183156
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
@@ -205,10 +178,10 @@ Everything else (should) work just like the original Eloquent model. Read more a
205178

206179
### Optional: Alias
207180

208-
You may also register an alias for the MongoDB model by adding the following to the alias array in `config/app.php`:
181+
You may also register an alias for the MongoDB model by adding the following to the alias array in `app/config/app.php`:
209182

210183
```php
211-
'Moloquent' => Jenssegers\Mongodb\Eloquent\Model::class,
184+
'Moloquent' => 'Jenssegers\Mongodb\Eloquent\Model',
212185
```
213186

214187
This will allow you to use the registered alias like:
@@ -257,32 +230,10 @@ Supported operations are:
257230
- hasCollection
258231
- index and dropIndex (compound indexes supported as well)
259232
- unique
260-
- background, sparse, expire, geospatial (MongoDB specific)
233+
- background, sparse, expire (MongoDB specific)
261234

262235
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
263236

264-
### Geospatial indexes
265-
266-
Geospatial indexes are handy for querying location-based documents. They come in two forms: `2d` and `2dsphere`. Use the schema builder to add these to a collection.
267-
268-
To add a `2d` index:
269-
270-
```php
271-
Schema::create('users', function($collection)
272-
{
273-
$collection->geospatial('name', '2d');
274-
});
275-
```
276-
277-
To add a `2dsphere` index:
278-
279-
```php
280-
Schema::create('users', function($collection)
281-
{
282-
$collection->geospatial('name', '2dsphere');
283-
});
284-
```
285-
286237
Extensions
287238
----------
288239

@@ -310,21 +261,6 @@ If you want to use MongoDB as your database backend, change the the driver in `c
310261
],
311262
```
312263

313-
If you want to use MongoDB to handle failed jobs, change the database in `config/queue.php`:
314-
315-
```php
316-
'failed' => [
317-
'database' => 'mongodb',
318-
'table' => 'failed_jobs',
319-
],
320-
```
321-
322-
And add the service provider in `config/app.php`:
323-
324-
```php
325-
Jenssegers\Mongodb\MongodbQueueServiceProvider::class,
326-
```
327-
328264
### Sentry
329265

330266
If you want to use this library with [Sentry](https://cartalyst.com/manual/sentry), then check out https://github.com/jenssegers/Laravel-MongoDB-Sentry
@@ -453,15 +389,6 @@ Aggregations can be combined with **where**:
453389
$sold = Orders::where('sold', true)->sum('price');
454390
```
455391

456-
Aggregations can be also used on subdocuments:
457-
458-
```php
459-
$total = Order::max('suborder.price');
460-
...
461-
```
462-
463-
**NOTE**: this aggreagtion only works with single subdocuments (like embedsOne) not subdocument arrays (like embedsMany)
464-
465392
**Like**
466393

467394
```php
@@ -539,10 +466,10 @@ User::where('tags', 'size', 3)->get();
539466
Selects documents where values match a specified regular expression.
540467

541468
```php
542-
User::where('name', 'regex', new \MongoDB\BSON\Regex("/.*doe/i"))->get();
469+
User::where('name', 'regex', new MongoRegex("/.*doe/i"))->get();
543470
```
544471

545-
**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.
472+
**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 MongoRegex object.
546473

547474
```php
548475
User::where('name', 'regexp', '/.*doe/i'))->get();
@@ -570,72 +497,6 @@ Performs a modulo operation on the value of a field and selects documents with a
570497
User::where('age', 'mod', [10, 0])->get();
571498
```
572499

573-
**Near**
574-
575-
**NOTE:** Specify coordinates in this order: `longitude, latitude`.
576-
577-
```php
578-
$users = User::where('location', 'near', [
579-
'$geometry' => [
580-
'type' => 'Point',
581-
'coordinates' => [
582-
-0.1367563,
583-
51.5100913,
584-
],
585-
],
586-
'$maxDistance' => 50,
587-
]);
588-
```
589-
590-
**GeoWithin**
591-
592-
```php
593-
$users = User::where('location', 'geoWithin', [
594-
'$geometry' => [
595-
'type' => 'Polygon',
596-
'coordinates' => [[
597-
[
598-
-0.1450383,
599-
51.5069158,
600-
],
601-
[
602-
-0.1367563,
603-
51.5100913,
604-
],
605-
[
606-
-0.1270247,
607-
51.5013233,
608-
],
609-
[
610-
-0.1450383,
611-
51.5069158,
612-
],
613-
]],
614-
],
615-
]);
616-
```
617-
618-
**GeoIntersects**
619-
620-
```php
621-
$locations = Location::where('location', 'geoIntersects', [
622-
'$geometry' => [
623-
'type' => 'LineString',
624-
'coordinates' => [
625-
[
626-
-0.144044,
627-
51.515215,
628-
],
629-
[
630-
-0.129545,
631-
51.507864,
632-
],
633-
],
634-
],
635-
]);
636-
```
637-
638-
639500
**Where**
640501

641502
Matches documents that satisfy a JavaScript expression. For more information check http://docs.mongodb.org/manual/reference/operator/query/where/#op._S_where
@@ -759,7 +620,7 @@ class User extends Eloquent {
759620

760621
public function groups()
761622
{
762-
return $this->belongsToMany('Group', null, 'user_ids', 'group_ids');
623+
return $this->belongsToMany('Group', null, 'users', 'groups');
763624
}
764625

765626
}
@@ -943,7 +804,7 @@ class Message extends Eloquent {
943804
These expressions will be injected directly into the query.
944805

945806
```php
946-
User::whereRaw(['age' => array('$gt' => 30, '$lt' => 40)])->get();
807+
User::whereRaw(['age' => array('$gt' => 30, '$lt' => 40]))->get();
947808
```
948809

949810
You can also perform raw expressions on the internal MongoCollection object. If this is executed on the model class, it will return a collection of models. If this is executed on the query builder, it will return the original response.
@@ -965,7 +826,7 @@ $cursor = DB::collection('users')->raw(function($collection)
965826
Optional: if you don't pass a closure to the raw method, the internal MongoCollection object will be accessible:
966827

967828
```php
968-
$model = User::raw()->findOne(['age' => array('$lt' => 18)]);
829+
$model = User::raw()->findOne(['age' => array('$lt' => 18]));
969830
```
970831

971832
The internal MongoClient and MongoDB objects can be accessed like this:
@@ -999,8 +860,7 @@ DB::collection('users')->where('name', 'John')
999860
You can apply projections to your queries using the `project` method.
1000861

1001862
```php
1002-
DB::collection('items')->project(['tags' => ['$slice' => 1]])->get();
1003-
DB::collection('items')->project(['tags' => ['$slice' => [3, 7]]])->get();
863+
DB::collection('items')->project(['tags' => array('$slice' => 1]))->get();
1004864
```
1005865

1006866
**Projections with Pagination**

composer.json

+10-17
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@
1111
],
1212
"license" : "MIT",
1313
"require": {
14-
"illuminate/support": "^5.6",
15-
"illuminate/container": "^5.6",
16-
"illuminate/database": "^5.6",
17-
"illuminate/events": "^5.6",
14+
"illuminate/support": "^5.1",
15+
"illuminate/container": "^5.1",
16+
"illuminate/database": "^5.1",
17+
"illuminate/events": "^5.1",
1818
"mongodb/mongodb": "^1.0.0"
19+
1920
},
2021
"require-dev": {
21-
"phpunit/phpunit": "^6.0|^7.0",
22+
"phpunit/phpunit": "^4.0|^5.0",
2223
"orchestra/testbench": "^3.1",
23-
"mockery/mockery": "^1.0",
24-
"satooshi/php-coveralls": "^2.0",
25-
"doctrine/dbal": "^2.5"
24+
"mockery/mockery": "^0.9",
25+
"satooshi/php-coveralls": "^0.6"
2626
},
2727
"autoload": {
2828
"psr-0": {
29-
"Jenssegers\\Mongodb": "src/"
29+
"Jenssegers\\Mongodb": "src/",
30+
"Jenssegers\\Eloquent": "src/"
3031
}
3132
},
3233
"autoload-dev": {
@@ -39,13 +40,5 @@
3940
"suggest": {
4041
"jenssegers/mongodb-session": "Add MongoDB session support to Laravel-MongoDB",
4142
"jenssegers/mongodb-sentry": "Add Sentry support to Laravel-MongoDB"
42-
},
43-
"extra": {
44-
"laravel": {
45-
"providers": [
46-
"Jenssegers\\Mongodb\\MongodbServiceProvider",
47-
"Jenssegers\\Mongodb\\MongodbQueueServiceProvider"
48-
]
49-
}
5043
}
5144
}

0 commit comments

Comments
 (0)