Issue #2372: Setting prefix doesn't work

XMLWordPrintableJSON

    • Type: Question
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: Laravel
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      peibinzhu has created Issue #2372: Setting prefix doesn't work in laravel-mongodb. This Jira ticket was filed by GromNaN

      Issue Text:

      • Laravel-mongodb Version: 3.9.0
      • PHP Version: 8.0.15
      • Database Driver & Version: 4.0.4

      Description:

      I set `prefix` in `config/database.php` file, but he doesn't work. My database table names are all prefixed, but I set them up, but it doesn't work, which makes me very distressed. hope it helps me

      Steps to reproduce

      1. Set `ll_`prefix` in `config/database.php`.

      return [
          'connections' => [
              'mongodb_log' => [
                  'driver'         => 'mongodb',
                  'url'            => env('DATABASE_URL'),
                  'host'           => explode(',', env('DB_HOST', '127.0.0.1')),
                  'port'           => env('DB_PORT', '27017'),
                  'database'       => env('DB_LOG', ''),
                  'username'       => env('DB_USERNAME', ''),
                  'password'       => env('DB_PASSWORD', ''),
                  'prefix'         => 'll_',
                  'prefix_indexes' => true,
                  'strict'         => true,
                  'engine'         => null,
                  'options'        => [
                      'database' => env('DB_MONGODB_AUTH_DATABASE', 'admin'),
                  ],
              ],
          ]
      ];

      2. Create a model class file.

      <?php
      
      declare(strict_types=1);
      
      namespace App\Models\Mongodb\Log;
      
      use Jenssegers\Mongodb\Eloquent\Model;
      
      class LogBootTimeLog extends Model
      {
          /**
           * The connection name for the model.
           *
           * @var string
           */
          protected $connection = 'mongodb_log';
      
          /**
           * The collection associated with the model.
           *
           * @var string
           */
          protected $collection = 'log_boot_time_log';
      } 

      3. Insert data into `ll_log_boot_time_log`

      <?php
      
      use App\Models\Mongodb\Log\LogBootTimeLog;
      
      $data = [
          'mac_address' => '00:00:00:00',
          'machine_id'  => 1,
          'runtime'     => 10,
          'touch_time'  => time(),
          'add_time'    => time(),
      ];
      LogBootTimeLog::insert($data); 

      4. The resulting sql statement.

      log_boot_time_log_202203.insertMany([{"mac_address":"00:00:00:00","machine_id":1,"runtime":10,"touch_time":1647454088,"add_time":1647454088}])

      This is not the result I want, I hope the `prefix` set will work.

      I want to effect:

      ll_log_boot_time_log_202203.insertMany([{"mac_address":"00:00:00:00","machine_id":1,"runtime":10,"touch_time":1647454088,"add_time":1647454088}])

      Expected behaviour

      I want to be able to set the prefix to make it take effect.

      Actual behaviour

      I want to be able to set the prefix to make it take effect.

            Assignee:
            Unassigned
            Reporter:
            TPM Jira Automations Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: