@@ -48,7 +48,11 @@ def initialize(cursor)
4848 #
4949 # @since 2.2.0
5050 def specification
51- { :coll_name => collection_name , :db_name => database . name , :cursor_ids => [ cursor . id ] }
51+ {
52+ coll_name : collection_name ,
53+ db_name : database . name ,
54+ cursor_ids : [ BSON ::Int64 . new ( cursor . id ) ] ,
55+ }
5256 end
5357
5458 class << self
@@ -59,23 +63,31 @@ class << self
5963 # OpKillCursors.update_cursors(spec, ids)
6064 #
6165 # @return [ Hash ] The specification.
62- # @return [ Array ] The ids to update with.
66+ # @return [ Array<Integer> ] The ids to update with.
6367 #
6468 # @since 2.3.0
6569 def update_cursors ( spec , ids )
66- spec . merge! ( cursor_ids : spec [ :cursor_ids ] & ids )
70+ # Ruby 2.5+ can & BSON::Int64 instances.
71+ # Ruby 2.4 and earlier cannot.
72+ # Convert stored ids to Ruby integers for compatibility with
73+ # older Rubies.
74+ ids = get_cursors_list ( spec ) & ids
75+ ids = ids . map do |cursor_id |
76+ BSON ::Int64 . new ( cursor_id )
77+ end
78+ spec . merge! ( cursor_ids : ids )
6779 end
6880
6981 # Get the list of cursor ids from a spec generated by this Builder.
7082 #
7183 # @example Get the list of cursor ids.
7284 # OpKillCursors.cursors(spec)
7385 #
74- # @return [ Hash ] The specification .
86+ # @return [ Array<Integer> ] The cursor ids .
7587 #
7688 # @since 2.3.0
7789 def get_cursors_list ( spec )
78- spec [ :cursor_ids ]
90+ spec [ :cursor_ids ] . map ( & :value )
7991 end
8092 end
8193 end
0 commit comments