Skip to content

Commit 45d8847

Browse files
committed
Update README.md
1 parent d45ae25 commit 45d8847

File tree

1 file changed

+50
-98
lines changed

1 file changed

+50
-98
lines changed

Diff for: README.md

+50-98
Original file line numberDiff line numberDiff line change
@@ -12,175 +12,133 @@ Installation
1212

1313
Add the package to your `composer.json` or install manually.
1414

15-
```yaml
16-
{
17-
"require": {
18-
"jenssegers/mongodb": "*"
15+
{
16+
"require": {
17+
"jenssegers/mongodb": "*"
18+
}
1919
}
20-
}
21-
```
2220

2321
Run `composer update` to download and install the package.
2422

2523
Add the service provider in `app/config/app.php`:
2624

27-
```php
28-
'Jenssegers\Mongodb\MongodbServiceProvider',
29-
```
25+
'Jenssegers\Mongodb\MongodbServiceProvider',
3026

3127
Usage
3228
-----
3329

3430
Tell your model to use the MongoDB model and a MongoDB collection (alias for table):
35-
36-
```php
37-
use Jenssegers\Mongodb\Model as Eloquent
38-
39-
class MyModel extends Eloquent {
40-
41-
protected $collection = 'mycollection';
42-
43-
}
44-
```
31+
32+
use Jenssegers\Mongodb\Model as Eloquent
33+
34+
class MyModel extends Eloquent {
35+
36+
protected $collection = 'mycollection';
37+
38+
}
4539

4640
Configuration
4741
-------------
4842

4943
The model will automatically check the database configuration array in `app/config/database.php` for a 'mongodb' item.
5044

51-
```php
52-
'mongodb' => array(
53-
'host' => 'localhost',
54-
'port' => 27017,
55-
'database' => 'database',
56-
),
57-
```
45+
'mongodb' => array(
46+
'host' => 'localhost',
47+
'port' => 27017,
48+
'database' => 'database',
49+
),
5850

5951
You can also specify the connection name in the model:
6052

61-
```php
62-
class MyModel extends Eloquent {
63-
64-
protected $connection = 'mongodb2';
65-
66-
}
67-
```
53+
class MyModel extends Eloquent {
54+
55+
protected $connection = 'mongodb2';
56+
57+
}
6858

6959
Examples
7060
--------
7161

7262
**Retrieving All Models**
7363

74-
```php
75-
$users = User::all();
76-
```
64+
$users = User::all();
7765

7866
**Retrieving A Record By Primary Key**
7967

80-
```php
81-
$user = User::find('517c43667db388101e00000f');
82-
```
68+
$user = User::find('517c43667db388101e00000f');
8369

8470
**Wheres**
8571

86-
```php
87-
$users = User::where('votes', '>', 100)->take(10)->get();
88-
```
72+
$users = User::where('votes', '>', 100)->take(10)->get();
8973

9074
**Or Statements**
9175

92-
```php
93-
$users = User::where('votes', '>', 100)->orWhere('name', 'John')->get();
94-
```
76+
$users = User::where('votes', '>', 100)->orWhere('name', 'John')->get();
9577

9678
**Using Where In With An Array**
9779

98-
```php
99-
$users = User::whereIn('age', array(16, 18, 20))->get();
100-
```
80+
$users = User::whereIn('age', array(16, 18, 20))->get();
10181

10282
When using `whereNotIn` objects will be returned if the field is non existant. Combine with `whereNotNull('age')` to leave out those documents.
10383

10484
**Using Where Between**
10585

106-
```php
107-
$users = User::whereBetween('votes', array(1, 100))->get();
108-
```
86+
$users = User::whereBetween('votes', array(1, 100))->get();
10987

11088
**Where null**
11189

112-
```php
113-
$users = User::whereNull('updated_at')->get();
114-
```
90+
$users = User::whereNull('updated_at')->get();
11591

11692
**Order By**
11793

118-
```php
119-
$users = User::orderBy('name', 'desc')->get();
120-
```
94+
$users = User::orderBy('name', 'desc')->get();
12195

12296
**Offset & Limit**
12397

124-
```php
125-
$users = User::skip(10)->take(5)->get();
126-
```
98+
$users = User::skip(10)->take(5)->get();
12799

128100
**Distinct**
129101

130102
Distinct requires a field for which to return the distinct values.
131103

132-
```php
133-
$users = User::distinct()->get(array('name'));
134-
// or
135-
$users = User::distinct('name')->get();
136-
```
104+
$users = User::distinct()->get(array('name'));
105+
// or
106+
$users = User::distinct('name')->get();
137107

138108
Distinct can be combined with **where**:
139109

140-
```php
141-
$users = User::where('active', true)->distinct('name')->get();
142-
```
110+
$users = User::where('active', true)->distinct('name')->get();
143111

144112
**Advanced Wheres**
145113

146-
```php
147-
$users = User::where('name', '=', 'John')->orWhere(function($query)
114+
$users = User::where('name', '=', 'John')->orWhere(function($query)
148115
{
149116
$query->where('votes', '>', 100)
150117
->where('title', '<>', 'Admin');
151118
})
152119
->get();
153-
```
154120

155121
**Group By**
156122

157123
Selected columns that are not grouped will be aggregated with the $last function.
158124

159-
```php
160-
$users = Users::groupBy('title')->get(array('title', 'name'));
161-
```
125+
$users = Users::groupBy('title')->get(array('title', 'name'));
162126

163127
**Aggregation**
164128

165-
```php
166-
$total = Order::count();
167-
$price = Order::max('price');
168-
$price = Order::min('price');
169-
$price = Order::avg('price');
170-
$total = Order::sum('price');
171-
```
129+
$total = Order::count();
130+
$price = Order::max('price');
131+
$price = Order::min('price');
132+
$price = Order::avg('price');
133+
$total = Order::sum('price');
172134

173135
Aggregations can be combined with **where**:
174136

175-
```php
176-
$sold = Orders::where('sold', true)->sum('price');
177-
```
137+
$sold = Orders::where('sold', true)->sum('price');
178138

179139
**Like**
180140

181-
```php
182-
$user = Comment::where('body', 'like', '%spam%')->get();
183-
```
141+
$user = Comment::where('body', 'like', '%spam%')->get();
184142

185143
**Inserts, updates and deletes**
186144

@@ -190,20 +148,14 @@ All basic insert, update, delete and select methods should be implemented.
190148

191149
Perform increments or decrements (default 1) on specified attributes:
192150

193-
```php
194-
User::where('name', 'John Doe')->increment('age');
195-
User::where('name', 'Bart De Wever')->decrement('weight', 50);
196-
```
151+
User::where('name', 'John Doe')->increment('age');
152+
User::where('name', 'Jaques')->decrement('weight', 50);
197153

198154
The number of updated objects is returned:
199155

200-
```php
201-
$count = User->increment('age');
202-
```
156+
$count = User->increment('age');
203157

204158
You may also specify additional columns to update:
205159

206-
```php
207-
User::where('age', '29')->increment('age', 1, array('group' => 'thirty something'));
208-
User::where('bmi', 30)->decrement('bmi', 1, array('category' => 'overweight'));
209-
```
160+
User::where('age', '29')->increment('age', 1, array('group' => 'thirty something'));
161+
User::where('bmi', 30)->decrement('bmi', 1, array('category' => 'overweight'));

0 commit comments

Comments
 (0)