Method: Mongo::Collection#count

Defined in:
lib/jmongo/collection.rb

#count(opts = {}) ⇒ Integer Also known as: size

Get the number of documents in this collection.

Returns:

  • (Integer)


658
659
660
661
662
663
664
665
# File 'lib/jmongo/collection.rb', line 658

def count(opts={})
  return @j_collection.count() if opts.empty?
  query = opts[:query] || opts['query'] || {}
  fields = opts[:fields] || opts['fields'] || {}
  limit = opts[:limit] || opts['limit'] || 0
  skip = opts[:skip] || opts['skip'] || 0
  @j_collection.get_count(to_dbobject(query), to_dbobject(fields), limit, skip)
end