Laravel Eloquent add support for ODM (Object Document Mapper) to Laravel. It's the same as Eloquent ORM, but with Documents, since MongoDB is a NoSQL database.
Laravel Eloquent adds support for ODM (Object Document Mapper) to Laravel. It's the same as Eloquent ORM, but with Documents, since MongoDB is a NoSQL database.
Table of contents
-----------------
...
...
@@ -110,7 +110,7 @@ Upgrading
In this new major release which supports the new MongoDB PHP extension, we also moved the location of the Model class and replaced the MySQL model class with a trait.
Please change all `Jenssegers\Mongodb\Model` references to `Jenssegers\Mongodb\Eloquent\Model` either at the top of your model files, or your registered alias.
Please change all `Jenssegers\Mongodb\Model` references to `Jenssegers\Mongodb\Eloquent\Model` either at the top of your model files or your registered alias.
```php
useJenssegers\Mongodb\Eloquent\Model;
...
...
@@ -154,7 +154,7 @@ docker-compose up
Configuration
-------------
You can use MongoDB either as a main database, either as a side database. To do so, add a new `mongodb` connection to `config/database.php`:
You can use MongoDB either as the main database, either as a side database. To do so, add a new `mongodb` connection to `config/database.php`:
```php
'mongodb'=>[
...
...
@@ -173,7 +173,7 @@ You can use MongoDB either as a main database, either as a side database. To do
],
```
For multiple servers or replica set configurations, set the host to array and specify each server host:
For multiple servers or replica set configurations, set the host to an array and specify each server host:
```php
'mongodb'=>[
...
...
@@ -186,7 +186,7 @@ For multiple servers or replica set configurations, set the host to array and sp
],
```
If you wish to use a connection string instead of a full key-value params, you can set it so. Check the documentation on MongoDB's URI format: https://docs.mongodb.com/manual/reference/connection-string/
If you wish to use a connection string instead of full key-value params, you can set it so. Check the documentation on MongoDB's URI format: https://docs.mongodb.com/manual/reference/connection-string/
```php
'mongodb'=>[
...
...
@@ -224,7 +224,7 @@ class Book extends Model
}
```
**NOTE:** MongoDb documents are automatically stored with an unique ID that is stored in the `_id` property. If you wish to use your own ID, substitude the `$primaryKey` property and set it to your own primary key attribute name.
**NOTE:** MongoDB documents are automatically stored with a unique ID that is stored in the `_id` property. If you wish to use your own ID, substitute the `$primaryKey` property and set it to your own primary key attribute name.
```php
useJenssegers\Mongodb\Eloquent\Model;
...
...
@@ -337,7 +337,7 @@ $users =
$users=User::whereIn('age',[16,18,20])->get();
```
When using `whereNotIn` objects will be returned if the field is nonexistent. Combine with `whereNotNull('age')` to leave out those documents.
When using `whereNotIn` objects will be returned if the field is non-existent. Combine with `whereNotNull('age')` to leave out those documents.
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.
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`:
...
...
@@ -785,7 +785,7 @@ class User extends Model
### EmbedsMany Relationship
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.
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.
**REMEMBER**: These relations return Eloquent collections, they don't return query builder objects!
...
...
@@ -998,7 +998,7 @@ MongoDB specific operations:
- expire
- geospatial
All other (unsupported) operations are implemented as dummy pass-through methods, because MongoDB does not use a predefined schema.
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 [Laravel Docs](https://laravel.com/docs/6.0/migrations#tables)
...
...
@@ -1031,11 +1031,11 @@ If you're using a hybrid MongoDB and SQL setup, you can define relationships acr
The model will automatically return a MongoDB-related or SQL-related relation based on the type of the related model.
If you want this functionality to work both ways, your SQL-models will need use the `Jenssegers\Mongodb\Eloquent\HybridRelations` trait.
If you want this functionality to work both ways, your SQL-models will need to use the `Jenssegers\Mongodb\Eloquent\HybridRelations` trait.
**This functionality only works for `hasOne`, `hasMany` and `belongsTo`.**
The MySQL model shoul use the `HybridRelations` trait:
The MySQL model should use the `HybridRelations` trait: