-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathquery-logging.txt
82 lines (63 loc) · 2.19 KB
/
query-logging.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
.. _laravel-query-logging:
====================
Enable Query Logging
====================
.. facet::
:name: genre
:values: reference
.. meta::
:keywords: monitoring, CRUD, code example
.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol
Overview
--------
In this guide, you can learn how to enable query logging in
{+odm-long+}. Query logging can help you debug your queries and monitor
database interactions.
.. include:: /includes/fundamentals/read-operations/before-you-get-started.rst
Enable Logs On a Connection
---------------------------
To enable logs on a connection, you can use the ``enableQueryLog()``
method on the ``DB`` facade. This method enables MongoDB command logging
on any queries that you perform on the database connection.
After you enable query logging, any queries you perform are stored in
memory. To retrieve the logs, use one of the following methods:
- ``getQueryLog()``: Returns a log of MongoDB queries
- ``getRawQueryLog()``: Returns a log of raw MongoDB queries
The following example enables query logging, performs some queries, then
prints the query log:
.. io-code-block::
:copyable: true
.. input:: /includes/fundamentals/read-operations/ReadOperationsTest.php
:language: php
:dedent:
:start-after: start-query-log
:end-before: end-query-log
:emphasize-lines: 1, 7
.. output::
:language: json
:visible: false
{
"query": "{ \"find\" : \"movies\", \"filter\" : { \"title\" : \"Carrie\" } }",
"bindings": [],
"time": 29476
}
{
"query": "{ \"find\" : \"movies\", \"filter\" : { \"year\" : { \"$lt\" : { \"$numberInt\" : \"2005\" } } } }",
"bindings": [],
"time": 29861
}
{
"query": "{ \"find\" : \"movies\", \"filter\" : { \"imdb.rating\" : { \"$gt\" : { \"$numberDouble\" : \"8.5\" } } } }",
"bindings": [],
"time": 27251
}
Additional Information
----------------------
To learn more about connecting to MongoDB, see the
:ref:`laravel-connect-to-mongodb`.
To learn how to retrieve data based on filter criteria, see the
:ref:`laravel-fundamentals-read-retrieve` guide.