Skip to content

Commit bd517f0

Browse files
Revert "RUBY-2565 Make View#count respect skip and limit (#2219)"
This reverts commit cbff0a7.
1 parent a02f324 commit bd517f0

File tree

3 files changed

+6
-70
lines changed

3 files changed

+6
-70
lines changed

lib/mongo/collection.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,14 @@ def count(filter = nil, options = {})
444444
# @param [ Hash ] filter A filter for matching documents.
445445
# @param [ Hash ] options Options for the operation.
446446
#
447-
# @option options :skip [ Integer ] The number of documents to skip.
448-
# @option options :hint [ Hash ] Override default index selection and force
447+
# @option opts :skip [ Integer ] The number of documents to skip.
448+
# @option opts :hint [ Hash ] Override default index selection and force
449449
# MongoDB to use a specific index for the query. Requires server version 3.6+.
450-
# @option options :limit [ Integer ] Max number of docs to count.
451-
# @option options :max_time_ms [ Integer ] The maximum amount of time to allow the
450+
# @option opts :limit [ Integer ] Max number of docs to count.
451+
# @option opts :max_time_ms [ Integer ] The maximum amount of time to allow the
452452
# command to run.
453-
# @option options :read [ Hash ] The read preference options.
454-
# @option options :collation [ Hash ] The collation to use.
453+
# @option opts [ Hash ] :read The read preference options.
454+
# @option opts [ Hash ] :collation The collation to use.
455455
#
456456
# @return [ Integer ] The document count.
457457
#

lib/mongo/collection/view/readable.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def comment(comment = nil)
142142
# * $near should be replaced with $geoWithin with $center
143143
# * $nearSphere should be replaced with $geoWithin with $centerSphere
144144
def count(opts = {})
145-
opts = Utils.shallow_symbolize_keys(@options.merge(opts))
146145
cmd = { :count => collection.name, :query => filter }
147146
cmd[:skip] = opts[:skip] if opts[:skip]
148147
cmd[:hint] = opts[:hint] if opts[:hint]
@@ -184,13 +183,11 @@ def count(opts = {})
184183
# command to run.
185184
# @option opts [ Hash ] :read The read preference options.
186185
# @option opts [ Hash ] :collation The collation to use.
187-
# @option opts [ Mongo::Session ] :session The session to use for the operation.
188186
#
189187
# @return [ Integer ] The document count.
190188
#
191189
# @since 2.6.0
192190
def count_documents(opts = {})
193-
opts = Utils.shallow_symbolize_keys(@options.merge(opts))
194191
pipeline = [:'$match' => filter]
195192
pipeline << { :'$skip' => opts[:skip] } if opts[:skip]
196193
pipeline << { :'$limit' => opts[:limit] } if opts[:limit]

spec/mongo/collection/view/readable_spec.rb

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -600,67 +600,6 @@
600600
end
601601
end
602602
end
603-
604-
context 'with limit' do
605-
let(:limit) { 6 }
606-
607-
it 'respects view limit' do
608-
expect(view.limit(limit).count).to eq(limit)
609-
end
610-
611-
it 'respects limit given as parameter' do
612-
expect(view.count(limit: limit)).to eq(limit)
613-
end
614-
end
615-
616-
context 'with skip' do
617-
let(:skip) { 6 }
618-
let(:expected) { 4 }
619-
620-
it 'respects view skip' do
621-
expect(view.skip(skip).count).to eq(expected)
622-
end
623-
624-
it 'respects skip given as parameter' do
625-
expect(view.count(skip: skip)).to eq(expected)
626-
end
627-
end
628-
end
629-
630-
describe '#count_documents' do
631-
let(:documents) do
632-
(1..10).map{ |i| { field: "test#{i}" }}
633-
end
634-
635-
before do
636-
authorized_collection.delete_many
637-
authorized_collection.insert_many(documents)
638-
end
639-
640-
context 'with limit' do
641-
let(:limit) { 6 }
642-
643-
it 'respects view limit' do
644-
expect(view.limit(limit).count_documents).to eq(limit)
645-
end
646-
647-
it 'respects limit given as parameter' do
648-
expect(view.count_documents(limit: limit)).to eq(limit)
649-
end
650-
end
651-
652-
context 'with skip' do
653-
let(:skip) { 6 }
654-
let(:expected) { 4 }
655-
656-
it 'respects view skip' do
657-
expect(view.skip(skip).count_documents).to eq(expected)
658-
end
659-
660-
it 'respects skip given as parameter' do
661-
expect(view.count_documents(skip: skip)).to eq(expected)
662-
end
663-
end
664603
end
665604

666605
describe '#distinct' do

0 commit comments

Comments
 (0)