diff --git a/src/CommandSubscriber.php b/src/CommandSubscriber.php index 569c7c909..5daa6e97a 100644 --- a/src/CommandSubscriber.php +++ b/src/CommandSubscriber.php @@ -48,6 +48,6 @@ private function logQuery(CommandSucceededEvent|CommandFailedEvent $event): void } } - $this->connection->logQuery(Document::fromPHP($command)->toCanonicalExtendedJSON(), [], $event->getDurationMicros()); + $this->connection->logQuery(Document::fromPHP($command)->toCanonicalExtendedJSON(), [], $event->getDurationMicros() / 1000); } } diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 75761080e..1f970d819 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -289,6 +289,8 @@ public function testQueryLog() DB::table('items')->get(); $this->assertCount(1, $logs = DB::getQueryLog()); $this->assertJsonStringEqualsJsonString('{"find":"items","filter":{}}', $logs[0]['query']); + $this->assertLessThan(10, $logs[0]['time'], 'Query time is in milliseconds'); + $this->assertGreaterThan(0.01, $logs[0]['time'], 'Query time is in milliseconds'); DB::table('items')->insert(['id' => $id = new ObjectId(), 'name' => 'test']); $this->assertCount(2, $logs = DB::getQueryLog());