Skip to content

Commit 6707e24

Browse files
committed
Update readme with a troubleshooting section
1 parent fd5e628 commit 6707e24

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

README.md

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,23 @@ You can connect to multiple servers or replica sets with the following configura
6767
Eloquent
6868
--------
6969

70-
Tell your model to use the MongoDB model and set the collection (alias for table) property. The lower-case, plural name of the class will be used for the collection name, unless another name is explicitly specified.
70+
This package includes a MongoDB enabled Eloquent class that you can use to define models for corresponding collections.
7171

7272
use Jenssegers\Mongodb\Model as Eloquent;
7373

74-
class MyModel extends Eloquent {
74+
class User extends Eloquent {}
75+
76+
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:
77+
78+
use Jenssegers\Mongodb\Model as Eloquent;
7579

76-
protected $collection = 'mycollection';
80+
class User extends Eloquent {
81+
82+
protected $collection = 'users_collection';
7783

7884
}
7985

80-
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:
86+
**NOTE:** Eloquent will also assume that each collection has a primary key column named id. You may define a `primaryKey` property to override this convention. Likewise, you may define a `connection` property to override the name of the database connection that should be used when utilizing the model.
8187

8288
use Jenssegers\Mongodb\Model as Eloquent;
8389

@@ -95,20 +101,17 @@ You may also register an alias for the MongoDB model by adding the following to
95101

96102
'Moloquent' => 'Jenssegers\Mongodb\Model',
97103

98-
This will allow you to use your registered alias like:
104+
This will allow you to use the registered alias like:
99105

100-
class MyModel extends Moloquent {
101-
102-
protected $collection = 'mycollection';
103-
104-
}
106+
class MyModel extends Moloquent {}
105107

106108
Query Builder
107109
-------------
108110

109111
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.
110112

111113
$users = DB::collection('users')->get();
114+
112115
$user = DB::collection('users')->where('name', 'John')->first();
113116

114117
If you did not change your default database connection, you will need to specify it when querying.
@@ -125,6 +128,7 @@ The database driver also has (limited) schema builder support. You can easily ma
125128
Schema::create('users', function($collection)
126129
{
127130
$collection->index('name');
131+
128132
$collection->unique('email');
129133
});
130134

@@ -137,27 +141,51 @@ Supported operations are:
137141
- unique
138142
- background, sparse, expire (MongoDB specific)
139143

140-
Read more about the schema builder on http://laravel.com/docs/schema
144+
All other (unsupported) operations are implemended 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
145+
146+
Extensions
147+
----------
141148

142-
Auth
143-
----
149+
### Auth
144150

145151
If you want to use Laravel's native Auth functionality, register this included service provider:
146152

147153
'Jenssegers\Mongodb\Auth\ReminderServiceProvider',
148154

149155
This service provider will slightly modify the internal DatabaseReminderRepository to add support for MongoDB based password reminders. If you don't use password reminders, you don't have to register this service provider and everything else should work just fine.
150156

151-
Sentry
152-
------
157+
### Sentry
153158

154159
If yo want to use this library with [Sentry](https://cartalyst.com/manual/sentry), then check out https://github.com/jenssegers/Laravel-MongoDB-Sentry
155160

156-
Sessions
157-
--------
161+
### Sessions
158162

159163
The MongoDB session driver is available in a separate package, check out https://github.com/jenssegers/Laravel-MongoDB-Session
160164

165+
Troubleshooting
166+
---------------
167+
168+
### Class 'MongoClient' not found in ...
169+
170+
The `MongoClient` class is part of the MongoDB PHP driver. Usually, this error means that you forgot to install, or did not install this driver correctly. You can find installation instructions for this driver at http://php.net/manual/en/mongo.installation.php.
171+
172+
To check if you have installed the driver correctly, run the following command:
173+
174+
$ php -i | grep 'Mongo'
175+
MongoDB Support => enabled
176+
177+
### Argument 2 passed to Illuminate\Database\Query\Builder::__construct() must be an instance of Illuminate\Database\Query\Grammars\Grammar, null given
178+
179+
To solve this, you will need to check two things. First check if your model is extending the correct class; this class should be `Jenssegers\Mongodb\Model`. Secondly, check if your model is using a MongoDB connection. If you did not change the default database connection in your database configuration file, you need to specify the MongoDB enabled connection. This is what your class should look like if you did not set up an alias and change the default database connection:
180+
181+
use Jenssegers\Mongodb\Model as Eloquent;
182+
183+
class User extends Eloquent {
184+
185+
protected $connection = 'mongodb';
186+
187+
}
188+
161189
Examples
162190
--------
163191

0 commit comments

Comments
 (0)