-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
cursor.pretty.txt
57 lines (39 loc) · 1.6 KB
/
cursor.pretty.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
===============
cursor.pretty()
===============
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. method:: cursor.pretty()
Configures the cursor to display results in an easy-to-read format.
The :method:`~cursor.pretty()` method has the following prototype form:
.. code-block:: javascript
db.collection.find(<query>).pretty()
Examples
--------
Consider the following document:
.. code-block:: javascript
db.books.save({
"_id" : ObjectId("54f612b6029b47909a90ce8d"),
"title" : "A Tale of Two Cities",
"text" : "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness...",
"authorship" : "Charles Dickens"})
By default, :method:`db.collection.find()` returns data in a dense format:
.. code-block:: javascript
db.books.find()
{ "_id" : ObjectId("54f612b6029b47909a90ce8d"), "title" : "A Tale of Two Cities", "text" : "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness...", "authorship" : "Charles Dickens" }
By using :method:`cursor.pretty()` you can set the cursor to return data in a
format that is easier for humans to parse:
.. code-block:: javascript
db.books.find().pretty()
{
"_id" : ObjectId("54f612b6029b47909a90ce8d"),
"title" : "A Tale of Two Cities",
"text" : "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness...",
"authorship" : "Charles Dickens"
}