mongodb的sql日志

在Yii2中是没有打印出mongodb的sql语句,故借用下log来查看吧。

在网上有说可以使用$model->find()->createCommand()->getRawSql();进行查询,但是经过测试我是没有成功过,

Yii2的版本:2.0.15.1

1.设置log的存放路径,当然这里是本地的

  common/config/local/bootstrap.php 敲入

Yii::setAlias('@customLog', '要存放的全路径名logs');

2.设置log配置 common/config/main.php下

$config = yiihelpersArrayHelper::merge([
    'components' => array_merge([
        'log' => [
            'targets' => [
                [
                    'class' => 'yiilogFileTarget',
                    'levels' => ['info'],
                    'categories' => ['yiimongodb*'],
                    'logFile' => '@customLog/mongodb.log',
                ]
            ],
        ],
    ]
    ),
]
);

  好了,查询下,看日志吧

原文地址:https://www.cnblogs.com/two-bees/p/10483833.html