Skip to content

Commit 650dbc9

Browse files
p-mongop
andauthored
RUBY-1817 Link countDocuments <-> estimatedDocumentCount documentation (#2044)
Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent c1245ea commit 650dbc9

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

source/tutorials/ruby-driver-crud-operations.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,36 @@ when querying and their corresponding methods as examples.
278278
Additional Query Operations
279279
---------------------------
280280

281+
``count_documents``
282+
Get the total number of documents matching a filter, or the total number
283+
of documents in a collection.
284+
285+
.. code-block:: ruby
286+
287+
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'music')
288+
289+
client[:artists].find(:name => 'Flying Lotus').count_documents
290+
291+
``estimated_document_count``
292+
Get an approximate number of documents in the collection.
293+
294+
Note that unlike ``count_documents``, ``estimated_document_count`` does not
295+
accept a filter.
296+
297+
.. code-block:: ruby
298+
299+
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'music')
300+
301+
client[:artists].estimated_document_count
302+
281303
``count``
282-
Get the total number of documents an operation returns.
304+
Get an approximate number of documents matching a filter, or an approximate
305+
number of documents in the collection.
306+
307+
*Deprecated:* The ``count`` method is deprecated and does not work in
308+
transactions. Please use ``count_documents`` to obtain an exact count of
309+
documents potentially matching a filter or ``estimated_document_count``
310+
to obtain an approximate number of documents in the collection.
283311

284312
.. code-block:: ruby
285313

0 commit comments

Comments
 (0)