linux - Laravel 没有从 env 文件中获取默认的 DB_CONNECTION 值

标签 linux laravel mongodb amazon-web-services

我在我的生产和开发环境中使用不同的 mongo 数据库。

我有不同的连接配置,因为 mongodb(生产连接名称)在 mongo atlas 集群上,所以它使用 dsn 连接,但是 mongodb1(开发连接名称)安装在本地,所以我使用主机和端口连接它。

我想为不同的环境使用不同的数据库连接,所以我在两种情况下都在 env 文件中设置了不同的 DB_CONNECTION。 我的制作是

     DB_CONNECTION=mongodb

为了发展它

     DB_CONNECTION=mongodb1

在我的 config/database.php 文件中
'default' => env('DB_CONNECTION', 'mysql'),

在我的连接数组中

    'mongodb' => [
        'driver' => 'mongodb',
        'dsn' => env('MONGO_DB_DSN'),
        'database' => env('MONGO_DB_DATABASE', 'uspl'),
        'username' => env('MONGO_DB_USERNAME', 'uspl'),
        'password' => env('MONGO_DB_PASSWORD', 'unfoldingskies'),
        'options' => array(
            'db' => 'uspl'
        )
    ],

    'mongodb1' => [
        'driver' => 'mongodb',
        'host' => env('MONGO_DB_HOST', 'localhost'),
        'port' => env('MONGO_DB_PORT', 27017),
        'database' => env('MONGO_DB_DATABASE'),
        'options' => []
    ],

我的开发环境出现错误 -> 数据库 [mongodb] 未配置。在文件中
/var/www/html/devBackend/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php 第 152 行

我试过 php artisan config:clear, cache:clear, composer dump-autoload 但没有效果

最佳答案

Laravel 不支持开箱即用的 MongoDB,因此您需要使用第 3 方包才能使用它。

As of this writing Laravel has the following database drivers:

  • MySQL 5.6+(版本政策)
  • PostgreSQL 9.4+(版本政策)
  • SQLite 3.8.8+
  • SQL Server 2017+(版本政策)

我在网上快速搜索了一下 this 3rd party package.

Laravel MongoDB

An Eloquent model and Query builder with support for MongoDB, using the original Laravel API. This library extends the original Laravel classes, so it uses exactly the same methods.

关于linux - Laravel 没有从 env 文件中获取默认的 DB_CONNECTION 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58502346/

相关文章:

Python 打印到/dev/usb/lp0

linux - ldd输出的解释

php - 无法使用 protonemedia/laravel-ffmpeg 为上传的视频添加水印

Laravel WhereIn 或 Wherein with where

php - undefined variable :$ Laravel 5

mongodb - 如何根据 MongoDB 中的另一个集合更新一个集合?

mongodb - 无法使用 MongoDB docker 镜像连接 Robomongo

linux - 如何拒绝对服务器的访问,同时允许用户在编辑 etc/hosts 时访问

c++ - 相同的程序可以在 C 中运行,但不能在 C++ 中运行(使用 linux 系统调用)

mongodb - 从 MongoDB 中的 ObjectId 获取所有文档和项目时间戳