Method: Mongo::Collection#estimated_document_count

Defined in:
lib/mongo/collection.rb

#estimated_document_count(options = {}) ⇒ Integer

Gets an estimate of the number of documents in the collection using the collection metadata.

Use #count_documents to retrieve the exact number of documents in the collection, or to count documents matching a filter.

Parameters:

  • options (Hash) (defaults to: {})

    Options for the operation.

Options Hash (options):

  • :max_time_ms (Integer)

    The maximum amount of time to allow the command to run for on the server.

  • :read (Hash)

    The read preference options.

  • :comment (Object)

    A user-provided comment to attach to this command.

  • :timeout_ms (Integer)

    The operation timeout in milliseconds. Must be a non-negative integer. An explicit value of 0 means infinite. The default value is unset which means the value is inherited from the collection or the database or the client.

Returns:

  • (Integer)

    The document count.

Since:

  • 2.6.0



751
752
753
# File 'lib/mongo/collection.rb', line 751

def estimated_document_count(options = {})
  View.new(self, {}, options).estimated_document_count(options)
end