lib/mongo/collection/view/readable.rb in mongo-2.7.0 vs lib/mongo/collection/view/readable.rb in mongo-2.7.1

- old
+ new

@@ -120,10 +120,11 @@ # @option opts :limit [ Integer ] Max number of docs to count. # @option opts :max_time_ms [ Integer ] The maximum amount of time to allow the # command to run. # @option opts [ Hash ] :read The read preference options. # @option opts [ Hash ] :collation The collation to use. + # @option opts [ Mongo::Session ] :session The session to use for the operation. # # @return [ Integer ] The document count. # # @since 2.0.0 # @@ -180,11 +181,13 @@ pipeline = [:'$match' => filter] pipeline << { :'$skip' => opts[:skip] } if opts[:skip] pipeline << { :'$limit' => opts[:limit] } if opts[:limit] pipeline << { :'$group' => { _id: nil, n: { :'$sum' => 1 } } } - opts.select! { |k, _| [:hint, :max_time_ms, :read, :collation].include?(k) } - aggregate(pipeline, opts).first['n'].to_i + opts.select! { |k, _| [:hint, :max_time_ms, :read, :collation, :session].include?(k) } + first = aggregate(pipeline, opts).first + return 0 unless first + first['n'].to_i end # Gets an estimate of the count of documents in a collection using collection metadata. # # @example Get the number of documents in the collection.