Set maxTimeMS at project level. To be applied to all queries.

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Fixed
    • Priority: Major - P3
    • 5.10.0
    • Affects Version/s: 5.10.0
    • 2
    • Needed
    • Hide

      1. What would you like to communicate to the user about this feature?

      Users can set the maxTimeMS option in config/database.php for the mongodb connection. This setting will apply to every operation sent by the query builder. That does not apply to raw commands sent directly using MongoDB\Collection methods.

      2. Would you like the user to see examples of the syntax and/or executable code and its output?

       

      return [
          'default' => env('DB_CONNECTION', 'mongodb'),
          'connections' => [
              'mongodb' => [
                  'driver' => 'mongodb',
                  'dsn' => env('MONGODB_DSN', 'mongodb://127.0.0.1:27017'),
                  'database' => env('MONGODB_DATABASE', 'app'),
                  'options' => [
                      'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'),
                      'maxTimeMS' => (int) env('MONGODB_MAX_TIME_MS', 2000),              
                  ],
              ],
          ],
      ];

       

       

      3. Which versions of the driver/connector does this apply to?

      Laravel-MongoDB 5.10

      Show
      1. What would you like to communicate to the user about this feature? Users can set the maxTimeMS option in config/database.php for the mongodb connection. This setting will apply to every operation sent by the query builder. That does not apply to raw commands sent directly using MongoDB\Collection methods. 2. Would you like the user to see examples of the syntax and/or executable code and its output?   return [     'default' => env('DB_CONNECTION', 'mongodb'),     'connections' => [         'mongodb' => [             'driver' => 'mongodb',             'dsn' => env('MONGODB_DSN', 'mongodb://127.0.0.1:27017'),             'database' => env('MONGODB_DATABASE', 'app'),             'options' => [                 'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'),                 'maxTimeMS' => (int) env('MONGODB_MAX_TIME_MS', 2000),                           ],         ],     ], ];     3. Which versions of the driver/connector does this apply to? Laravel-MongoDB 5.10
    • None
    • None
    • None
    • None
    • None
    • None

      Introduction

      I don't really know the correct workflow for receive feedback on this potential feature. I hope opening this issue is the right way to do it.

      If this isn't the correct workflow, I apologize.

      What is the feature.

      The "maxTimeMS" configuration can be applied at the query level using the "timeout()" method, like this:

      NiceModel::timeout(2)->find()

      It cannot be applied at the cluster or project level. You need to apply it to each query individually.

      Why this is importante?

      Let's say your company defines a policy such as: "All queries should take a maximum of 2 seconds to run. Keep them performant."

      This also helps prevent extremely long-running queries. For example, a query should not take more than 5 minutes to complete.

      How to use is?

      We can configure this at connection options array like this:

      'mongodb' => [
      'driver' => 'mongodb',
      'dsn' => env('MONGODB_DSN'),
      'database' => env('MONGODB_CONVENIA', 'convenia'),
      'options' => [
      'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'),
      'maxTimeMS' => env('DB_MAX_TIME_MS', 2000),
      ],
      ],

      If the user calls the ->timeout() method than it takes precedence. The project level configuration acts like a default configuration that can be overrided.

      Do i have a MR?

      Yeah!

      I already have the code tested with a very small change to achieve this.

      All tests are passing, and I believe the implementation is safe. I haven't noticed any side effects.

      I'm just trying to figure out which branch I should target for the merge request and where this feature should be documented.

              Assignee:
              Jérôme Tamarelle
              Reporter:
              João Leonardo Lemos (EXT)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: