-
Notifications
You must be signed in to change notification settings - Fork 43
P2: Usage examples moved to appropriate pages #624
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
Changes from all commits
f224187
7a4bbd1
108ad3f
da68352
a96adfd
dd30a03
1cdadaf
66e0749
92b5f5d
1fae4d5
7cbdded
53545a5
1266781
4cb32bc
890146e
560672c
895a762
a3f187e
8520274
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
.. _java-usage-count: | ||
.. _java-count: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: per the renaming guidance, leave old anchors in place There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this tag down to the Count Documents Example: Full File, so that anyone referencing it will still be taking to the example. |
||
=============== | ||
Count Documents | ||
=============== | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: count, number, size, collection, code example | ||
:description: Learn about how to count the number of documents in a collection in the {+driver-long+}. | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 2 | ||
:class: singlecol | ||
|
||
Overview | ||
-------- | ||
|
||
There are two instance methods in the ``MongoCollection`` class that you can | ||
call to count the number of documents in a collection: | ||
In this guide, you can learn how to count the number of documents in your | ||
MongoDB collections. There are two instance methods in the | ||
rustagir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``MongoCollection`` class that you can call to count the number of documents in | ||
a collection: | ||
|
||
- ``countDocuments()`` returns the number of documents in the collection | ||
that match a specified query. If you specify an empty query filter, | ||
|
@@ -74,17 +91,19 @@ specify the behavior of the call: | |
|
||
Both methods return the number of matching documents as a ``long`` primitive. | ||
|
||
Example | ||
------- | ||
.. _java-usage-count: | ||
|
||
Count Documents Example: Full File | ||
---------------------------------- | ||
|
||
.. include:: /includes/crud/example-intro.rst | ||
|
||
The following example estimates the number of documents in the | ||
``movies`` collection in the ``sample_mflix`` database, and then returns | ||
an accurate count of the number of documents in the ``movies`` | ||
collection with ``Canada`` in the ``countries`` field. | ||
|
||
.. include:: /includes/connect-guide-note.rst | ||
|
||
.. literalinclude:: /includes/usage-examples/code-snippets/CountDocuments.java | ||
.. literalinclude:: /includes/crud/CountDocuments.java | ||
:language: java | ||
|
||
If you run the preceding sample code, you should see output that looks something | ||
|
@@ -98,10 +117,21 @@ like this (exact numbers can vary depending on your data): | |
|
||
.. include:: /includes/legacy-redirect.rst | ||
|
||
For additional information on the classes and methods mentioned on this | ||
page, see the following API Documentation: | ||
Additional Information | ||
---------------------- | ||
|
||
API Documentation | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
For more information about the classes and methods used to count documents, see the following API documentation: | ||
|
||
- `countDocuments() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#countDocuments()>`__ | ||
- `estimatedDocumentCount() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#estimatedDocumentCount()>`__ | ||
- `CountOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/CountOptions.html>`__ | ||
- `EstimatedDocumentCountOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/EstimatedDocumentCountOptions.html>`__ | ||
|
||
Server Manual Entries | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
- :manual:`db.collection.countDocuments() </reference/method/db.collection.countDocuments/>` | ||
- :manual:`db.collection.estimatedDocumentCount() </reference/method/db.collection.estimatedDocumentCount/>` |
Uh oh!
There was an error while loading. Please reload this page.