File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -278,8 +278,36 @@ when querying and their corresponding methods as examples.
278
278
Additional Query Operations
279
279
---------------------------
280
280
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
+
281
303
``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.
283
311
284
312
.. code-block:: ruby
285
313
You can’t perform that action at this time.
0 commit comments