Skip to content

DOCS-2147: Add reference for cursor.{itcount,pretty} #2215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion source/includes/ref-toc-method-cursor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: "Controls the number of documents MongoDB will return to the client
---
name: ":method:`cursor.count()`"
file: /reference/method/cursor.count
description: "Returns a count of the documents in a cursor."
description: "Returns the total number of documents in a cursor."
---
name: ":method:`cursor.explain()`"
file: /reference/method/cursor.explain
Expand All @@ -26,6 +26,10 @@ name: ":method:`cursor.hint()`"
file: /reference/method/cursor.hint
description: "Forces MongoDB to use a specific index for a query."
---
name: ":method:`cursor.itcount()`"
file: /reference/method/cursor.itcount
description: "Returns the number of documents remaining in a cursor."
---
name: ":method:`cursor.limit()`"
file: /reference/method/cursor.limit
description: "Constrains the size of a cursor's result set."
Expand Down Expand Up @@ -54,6 +58,10 @@ name: ":method:`cursor.objsLeftInBatch()`"
file: /reference/method/cursor.objsLeftInBatch
description: "Returns the number of documents left in the current cursor batch."
---
name: ":method:`cursor.pretty()`"
file: /reference/method/cursor.pretty
description: "Configures the cursor to display results in an easy-to-read format."
---
name: ":method:`cursor.readPref()`"
file: /reference/method/cursor.readPref
description: "Specifies a :term:`read preference` to a cursor to control how the client directs queries to a :term:`replica set`."
Expand Down
25 changes: 25 additions & 0 deletions source/reference/method/cursor.itcount.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
================
cursor.itcount()
================

.. default-domain:: mongodb

Definition
----------

.. method:: cursor.itcount()

Counts the number of documents remaining in a cursor.

:method:`~cursor.itcount()` is similar to :method:`cursor.count()`, but
actually executes the query on an existing iterator, exhausting its contents
in the process.

The :method:`~cursor.itcount()` method has the following
prototype form:

.. code-block:: javascript

db.collection.find(<query>).itcount()

.. seealso:: :method:`cursor.count()`
51 changes: 51 additions & 0 deletions source/reference/method/cursor.pretty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
===============
cursor.pretty()
===============

.. default-domain:: mongodb

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"
}