Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I get mongodb query log in Laravel

The code is:

DB::enableQueryLog();
User::find(334);        // MySql
$res = $this->subjects->simplePage()->paginate(); //Mongo
dd(DB::getQueryLog());

and the output is:

array:1 [
  0 => array:3 [
    "query" => "select * from `user` where `user`.`id` = ? and `user`.`deleted_at` is null limit 1"
    "bindings" => array:1 [
      0 => 334
    ]
    "time" => 23.53
  ]
]

Is there anything wrong? thanks a lot.

like image 766
zymaozZ Avatar asked Oct 28 '25 05:10

zymaozZ


1 Answers

DB::getQueryLog() will use the default connection, I think your default connection is mysql. so it print the mysql query log.

Try to use your mongodb connection, something like this:

DB::connection('mongodb')->enableQueryLog();
DB::connection('mongodb')->getQueryLog();
like image 146
TsaiKoga Avatar answered Oct 29 '25 20:10

TsaiKoga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!