Skip to content

Commit c2c91a2

Browse files
committed
2843
1 parent 4f5e06d commit c2c91a2

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

lib/mongo/collection.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ def count(filter = nil, options = {})
493493
# command to run.
494494
# @option options :read [ Hash ] The read preference options.
495495
# @option options :collation [ Hash ] The collation to use.
496+
# @option options [ Session ] :session The session to use.
496497
#
497498
# @return [ Integer ] The document count.
498499
#

lib/mongo/collection/view/readable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ def count(opts = {})
207207
# command to run.
208208
# @option opts [ Hash ] :read The read preference options.
209209
# @option opts [ Hash ] :collation The collation to use.
210+
# @option opts [ Mongo::Session ] :session The session to use for the operation.
210211
#
211212
# @return [ Integer ] The document count.
212213
#

spec/mongo/collection/view/readable_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,32 @@
671671
end
672672
end
673673

674+
describe '#count_documents' do
675+
676+
let(:result) do
677+
new_view.count_documents(options)
678+
end
679+
680+
context 'when session is given' do
681+
let(:subscriber) { Mrss::EventSubscriber.new }
682+
683+
before do
684+
authorized_collection.client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
685+
end
686+
687+
it 'passes the session' do
688+
authorized_collection.client.with_session do |session|
689+
session_id = session.session_id
690+
691+
authorized_collection.count_documents({}, session: session)
692+
693+
event = subscriber.single_command_started_event('aggregate')
694+
event.command['lsid'].should == session_id
695+
end
696+
end
697+
end
698+
end
699+
674700
describe '#distinct' do
675701

676702
context 'when incorporating read concern' do

0 commit comments

Comments
 (0)