Skip to content

Commit 1d05ba3

Browse files
committed
Updating readme
1 parent d0822e7 commit 1d05ba3

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

README.md

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ Laravel MongoDB
33

44
[![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) [![Build Status](http://img.shields.io/travis/jenssegers/laravel-mongodb.svg)](https://travis-ci.org/jenssegers/laravel-mongodb) [![Coverage Status](http://img.shields.io/coveralls/jenssegers/laravel-mongodb.svg)](https://coveralls.io/r/jenssegers/laravel-mongodb?branch=master)
55

6-
An Eloquent model and Query builder with support for MongoDB, inspired by LMongo, but using the original Laravel methods. *This library extends the original Laravel classes, so it uses exactly the same methods.*
6+
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.*
77

88
### Upgrading from v1 to v2
99

10-
In this new version, embedded documents are no longer saved to the parent model using an attribute with a leading underscore. If you have a relation like `embedsMany('Book')`, these books are now stored under `$model['books']` instead of `$model['_books']`. This was changed so that embedded relations are less confusing for new developers.
10+
In this new version, embedded documents are no longer saved to the parent model using an attribute with a leading underscore. If you have a relation like `embedsMany('Book')`, these books are now stored under `$model['books']` instead of `$model['_books']`. This was changed to make embedded relations less confusing for new developers.
1111

12-
If you want to upgrade to this new version, without having to change all your existing database objects, you can modify your relations to use a local key including the underscore:
12+
If you want to upgrade to this new version without having to change all your existing database objects, you can modify your embedded relations to use a non-default local key including the underscore:
1313

1414
$this->embedsMany('Book', '_books');
1515

16-
You can see the changelog at https://github.com/jenssegers/laravel-mongodb/releases/tag/v2.0.0
16+
Read the full changelog at https://github.com/jenssegers/laravel-mongodb/releases/tag/v2.0.0
1717

1818
Installation
1919
------------
@@ -75,7 +75,7 @@ Tell your model to use the MongoDB model and set the collection (alias for table
7575

7676
}
7777

78-
If you are using a different database driver as the default one, you will need to specify the mongodb connection within your model by changing the `connection` property:
78+
If you are using a different database driver as the default one, you will need to specify the mongodb connection name within your model by changing the `connection` property:
7979

8080
use Jenssegers\Mongodb\Model as Eloquent;
8181

@@ -104,15 +104,15 @@ This will allow you to use your registered alias like:
104104
Query Builder
105105
-------------
106106

107-
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.
107+
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.
108108

109-
// With custom connection
110-
$user = DB::connection('mongodb')->collection('users')->get();
111-
112-
// Using default connection
113109
$users = DB::collection('users')->get();
114110
$user = DB::collection('users')->where('name', 'John')->first();
115111

112+
If you did not change your default dabatase connection, you will need to specify it when querying.
113+
114+
$user = DB::connection('mongodb')->collection('users')->get();
115+
116116
Read more about the query builder on http://laravel.com/docs/queries
117117

118118
Schema
@@ -429,7 +429,7 @@ Other relations are not yet supported, but may be added in the future. Read more
429429

430430
### EmbedsMany Relations
431431

432-
If you want to embed documents, rather than referencing them, you can use the `embedsMany` relation. This relation is similar to the `hasMany` relation, but embeds the models in the parent object.
432+
If you want to embed models, rather than referencing them, you can use the `embedsMany` relation. This relation is similar to the `hasMany` relation, but embeds the models inside the parent object.
433433

434434
use Jenssegers\Mongodb\Model as Eloquent;
435435

@@ -442,15 +442,15 @@ If you want to embed documents, rather than referencing them, you can use the `e
442442

443443
}
444444

445-
Now we can access the user's books through the dynamic property:
445+
You access the embedded models through the dynamic property:
446446

447447
$books = User::first()->books;
448448

449-
When using embedded documents, there will also be an inverse relation available:
449+
The inverse relation is auto*magically* available, you don't need to define this reverse relation.
450450

451451
$user = $book->user;
452452

453-
Inserting and updating embedded documents works just like the `belongsTo` relation:
453+
Inserting and updating embedded models works similar to the `hasMany` relation:
454454

455455
$book = new Book(array('title' => 'A Game of Thrones'));
456456

@@ -460,39 +460,46 @@ Inserting and updating embedded documents works just like the `belongsTo` relati
460460
// or
461461
$book = $user->books()->create(array('title' => 'A Game of Thrones'))
462462

463-
Modifying and saving embedded documents is as easy as (available since release 2.0.0):
463+
You can update embedded models using their `save` method (available since release 2.0.0):
464464

465465
$book = $user->books()->first();
466466

467467
$book->title = 'A Game of Thrones';
468468

469469
$book->save();
470470

471-
You can remove an embedded document by using the `destroy()` method on the relation, or the `delete` method on the model (available since release 2.0.0):
471+
You can remove an embedded model by using the `destroy` method on the relation, or the `delete` method on the model (available since release 2.0.0):
472472

473473
$book = $user->books()->first();
474474

475475
$book->delete();
476476
// or
477477
$user->books()->destroy($book);
478478

479-
If you want to add or remove embedded documents, without persistence, you can use the `associate` and `dissociate` methods. To write the changes to the database, simply save the parent object:
479+
If you want to add or remove an embedded model, without touching the database, you can use the `associate` and `dissociate` methods. To eventually write the changes to the database, save the parent object:
480480

481481
$user->books()->associate($book);
482482

483483
$user->save();
484484

485-
Again, you may override the conventional local key by passing a second argument to the embedsMany method:
485+
Like other relations, embedsMany assumes the local key of the relationship based on the model name. You can override the default local key by passing a second argument to the embedsMany method:
486486

487487
return $this->embedsMany('Book', 'local_key');
488488

489-
Embedded relations will return a Collection of embedded items instead of a query builder. To simulate a more query-like behavior, embedded relations return a modified version of the Collection class with support for the following operations: `where($key, $operator, $value)` and `orderBy($key, $direction)`. This allows you to do query the collection results like this:
489+
Embedded relations will return a Collection of embedded items instead of a query builder. To allow a more query-like behavior, embedded relations will return a modified version of the Collection class with support for the following operations:
490+
491+
- where($key, $operator, $value)
492+
- orderBy($key, $direction)
493+
494+
This allows you to execute simple queries on the collection results:
490495

491496
$books = $user->books()->where('rating', '>', 5)->orderBy('title')->get();
492497

498+
**Note:** Because embedded models are not stored in a separate collection, you can not query all of embedded models. You will always have to access them through the parent model.
499+
493500
### EmbedsOne Relations
494501

495-
There is also an EmbedsOne relation, which works similar to the EmbedsMany relation, but only stores one embedded model.
502+
The embedsOne relation is similar to the EmbedsMany relation, but only embeds a single model.
496503

497504
use Jenssegers\Mongodb\Model as Eloquent;
498505

@@ -505,11 +512,11 @@ There is also an EmbedsOne relation, which works similar to the EmbedsMany relat
505512

506513
}
507514

508-
Now we can access the book's author through the dynamic property:
515+
You access the embedded models through the dynamic property:
509516

510517
$author = Book::first()->author;
511518

512-
Inserting and updating the embedded document works just like the `embedsMany` relation:
519+
Inserting and updating embedded models works similar to the `hasOne` relation:
513520

514521
$author = new Author(array('name' => 'John Doe'));
515522

@@ -519,14 +526,14 @@ Inserting and updating the embedded document works just like the `embedsMany` re
519526
// or
520527
$author = $book->author()->create(array('name' => 'John Doe'));
521528

522-
Modifying and saving the embedded document:
529+
You can update the embedded model using the `save` method (available since release 2.0.0):
523530

524531
$author = $book->author;
525532

526533
$author->name = 'Jane Doe';
527534
$author->save();
528535

529-
Swapping the embedded document:
536+
You can replace the embedded model with a new model like this:
530537

531538
$newAuthor = new Author(array('name' => 'Jane Doe'));
532539
$book->author()->save($newAuthor);
@@ -589,7 +596,7 @@ Optional: if you don't pass a closure to the raw method, the internal MongoColle
589596

590597
$model = User::raw()->findOne(array('age' => array('$lt' => 18)));
591598

592-
The MongoClient and MongoDB objects can be accessed like this:
599+
The internal MongoClient and MongoDB objects can be accessed like this:
593600

594601
$client = DB::getMongoClient();
595602
$db = DB::getMongoDB();
@@ -611,7 +618,7 @@ Update or insert a document. Additional options for the update method are passed
611618

612619
**Projections**
613620

614-
You can apply projections to your queries using the `project()` method.
621+
You can apply projections to your queries using the `project` method.
615622

616623
DB::collection('items')->project(array('tags' => array('$slice' => 1)))->get();
617624

0 commit comments

Comments
 (0)