PHPackages                             nantaburi/mongodb-sql-model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. nantaburi/mongodb-sql-model

ActiveLibrary[Database &amp; ORM](/categories/database)

nantaburi/mongodb-sql-model
===========================

Mongodb using SQL style

1.0.30(4y ago)0124MITPHPPHP &gt;=7.2.0

Since Jul 8Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ManUnit/monngodb-php-sql-style)[ Packagist](https://packagist.org/packages/nantaburi/mongodb-sql-model)[ Docs](https://github.com/ManUnit/monngodb-php-sql-style)[ RSS](/packages/nantaburi-mongodb-sql-model/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (1)Versions (28)Used By (0)

mongodb-sql-style
=================

[](#mongodb-sql-style)

Installing

```
composer require nantaburi/mongodb-sql-model

```

Mongodb using SQL style

- Configuraton add setting in config/database.php of laravel
- Authorization Database default as admin if no value \[options\]\[authen\_db\]

```
'mongodb' => [
    'driver' => 'mongodb',
    'host' => env('MONGO_DB_HOST', '127.0.0.1'),
    'port' => env('MONGO_DB_PORT', 27017),
    'database' => env('MONGO_DB_DATABASE', 'marcompany'),
    'username' => env('MONGO_DB_USERNAME', 'maradmin'),
    'password' => env('MONGO_DB_PASSWORD', 'password'),
    'options' => [
        'authen_db' => env('DB_AUTHENTICATION_DATABASE', 'admin'),
    ],
],

```

Run Nantabury/Mongodb standalone without laravel :

- if you don't have laravel wasn't installed you have only base on composer package go to create file `.env` under project's directory and then copy all below to .env

```
# Nantaburi .env file

MONGO_DB_HOST='127.0.0.1'
MONGO_DB_PORT='27017'
MONGO_DB_DATABASE='products'
MONGO_DB_USERNAME='root'
MONGO_DB_PASSWORD='password'

```

---

- Using Laravel for SQL query style example below
    - Create Model - using command ` php artisan make:model UserDbModel` at laravel root project and insert `use Nantaburi\Mongodb\MongoNativeDriver\Model  ` on top
        - ex-fillable used to be `protected $fillable = ["useid","username","lastname","password"] ` will replace with $schema as example below
        - Example : `protected $schema [ "userscollection" , ["useid","username","lastname","password"] ] `
        - Magic create index with two ways
            - first way : add array with key \[ Index =&gt; true \] if you want to add option Unique just add more key \[ 'Index' =&gt; true , 'Unique' =&gt; true \]
            - secound way : do multiple keys with create key `"$__MULTIPLE_INDEX_01" `on same level of collection change at the end `_01` to be other once you have more one multiple keys you can use `_02` even `_AB` support as well
        - Magic create collection for counters auto increasement number by add `'AutoInc' => true , ` and also have option `'AutoInc' => true , 'AutoIncStartwith' => 10,` default datatype as double max number can be 2^1023
        - Magic creation of Index and Magic counter will auto create affective once you run first insert or you can do \[NameModel\]::InitIndexAutoInc()
            - Example : run at Laravel controller just first time or do change schema `UserModel::InitIndexAutoInc()`
    - to protect update option add `'UpdateProtected'=>true` once you inserted and do you want to protect update such as price , ID Card number , you can put option example `idcard => [ 'UpdateProtected'=>true  ]` into option of that field

```
