mongo 2.1.2 → 2.2.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +10 -3
  5. data/Rakefile +1 -7
  6. data/lib/csasl/csasl.bundle +0 -0
  7. data/lib/mongo/auth/user/view.rb +1 -1
  8. data/lib/mongo/bulk_write.rb +7 -1
  9. data/lib/mongo/client.rb +17 -15
  10. data/lib/mongo/cluster.rb +4 -2
  11. data/lib/mongo/collection.rb +36 -2
  12. data/lib/mongo/collection/view.rb +24 -21
  13. data/lib/mongo/collection/view/aggregation.rb +5 -42
  14. data/lib/mongo/collection/view/builder.rb +20 -0
  15. data/lib/mongo/collection/view/builder/aggregation.rb +98 -0
  16. data/lib/mongo/collection/view/builder/find_command.rb +111 -0
  17. data/lib/mongo/collection/view/builder/flags.rb +62 -0
  18. data/lib/mongo/collection/view/builder/map_reduce.rb +134 -0
  19. data/lib/mongo/collection/view/builder/modifiers.rb +80 -0
  20. data/lib/mongo/collection/view/builder/op_query.rb +83 -0
  21. data/lib/mongo/collection/view/explainable.rb +15 -0
  22. data/lib/mongo/collection/view/immutable.rb +5 -12
  23. data/lib/mongo/collection/view/iterable.rb +24 -2
  24. data/lib/mongo/collection/view/map_reduce.rb +18 -27
  25. data/lib/mongo/collection/view/readable.rb +70 -112
  26. data/lib/mongo/collection/view/writable.rb +23 -7
  27. data/lib/mongo/cursor.rb +76 -25
  28. data/lib/mongo/cursor/builder.rb +18 -0
  29. data/lib/mongo/cursor/builder/get_more_command.rb +71 -0
  30. data/lib/mongo/cursor/builder/kill_cursors_command.rb +62 -0
  31. data/lib/mongo/cursor/builder/op_get_more.rb +61 -0
  32. data/lib/mongo/cursor/builder/op_kill_cursors.rb +56 -0
  33. data/lib/mongo/database.rb +2 -2
  34. data/lib/mongo/database/view.rb +9 -5
  35. data/lib/mongo/dbref.rb +3 -3
  36. data/lib/mongo/error.rb +1 -0
  37. data/lib/mongo/error/invalid_write_concern.rb +35 -0
  38. data/lib/mongo/grid/file/chunk.rb +2 -2
  39. data/lib/mongo/index/view.rb +5 -2
  40. data/lib/mongo/operation.rb +1 -0
  41. data/lib/mongo/operation/commands.rb +2 -0
  42. data/lib/mongo/operation/commands/aggregate.rb +39 -45
  43. data/lib/mongo/operation/commands/aggregate/result.rb +54 -68
  44. data/lib/mongo/operation/commands/collections_info.rb +38 -36
  45. data/lib/mongo/operation/commands/collections_info/result.rb +17 -15
  46. data/lib/mongo/operation/commands/command.rb +24 -22
  47. data/lib/mongo/operation/commands/find.rb +27 -0
  48. data/lib/mongo/operation/commands/find/result.rb +62 -0
  49. data/lib/mongo/operation/commands/get_more.rb +27 -0
  50. data/lib/mongo/operation/commands/get_more/result.rb +62 -0
  51. data/lib/mongo/operation/commands/indexes.rb +41 -39
  52. data/lib/mongo/operation/commands/list_collections.rb +25 -31
  53. data/lib/mongo/operation/commands/list_collections/result.rb +63 -81
  54. data/lib/mongo/operation/commands/list_indexes.rb +27 -35
  55. data/lib/mongo/operation/commands/list_indexes/result.rb +67 -85
  56. data/lib/mongo/operation/commands/map_reduce.rb +29 -37
  57. data/lib/mongo/operation/commands/map_reduce/result.rb +85 -88
  58. data/lib/mongo/operation/commands/parallel_scan.rb +29 -33
  59. data/lib/mongo/operation/commands/parallel_scan/result.rb +34 -42
  60. data/lib/mongo/operation/commands/user_query.rb +40 -38
  61. data/lib/mongo/operation/commands/users_info.rb +24 -29
  62. data/lib/mongo/operation/commands/users_info/result.rb +13 -11
  63. data/lib/mongo/operation/object_id_generator.rb +36 -0
  64. data/lib/mongo/operation/result.rb +30 -0
  65. data/lib/mongo/operation/specifiable.rb +35 -1
  66. data/lib/mongo/operation/write/bulk/bulkable.rb +4 -3
  67. data/lib/mongo/operation/write/bulk/delete/result.rb +18 -25
  68. data/lib/mongo/operation/write/bulk/legacy_mergable.rb +2 -2
  69. data/lib/mongo/operation/write/command/delete.rb +3 -2
  70. data/lib/mongo/operation/write/command/insert.rb +4 -2
  71. data/lib/mongo/operation/write/command/update.rb +6 -3
  72. data/lib/mongo/operation/write/gle.rb +2 -1
  73. data/lib/mongo/operation/write/idable.rb +19 -2
  74. data/lib/mongo/options/mapper.rb +22 -0
  75. data/lib/mongo/protocol/bit_vector.rb +3 -3
  76. data/lib/mongo/protocol/delete.rb +15 -5
  77. data/lib/mongo/protocol/get_more.rb +10 -5
  78. data/lib/mongo/protocol/insert.rb +1 -6
  79. data/lib/mongo/protocol/kill_cursors.rb +14 -1
  80. data/lib/mongo/protocol/message.rb +32 -8
  81. data/lib/mongo/protocol/serializers.rb +15 -16
  82. data/lib/mongo/protocol/update.rb +35 -12
  83. data/lib/mongo/server/connectable.rb +3 -1
  84. data/lib/mongo/server/connection.rb +5 -5
  85. data/lib/mongo/server/description.rb +8 -2
  86. data/lib/mongo/server/description/features.rb +2 -1
  87. data/lib/mongo/server/monitor.rb +1 -12
  88. data/lib/mongo/server/monitor/connection.rb +30 -26
  89. data/lib/mongo/server_selector/selectable.rb +21 -4
  90. data/lib/mongo/uri.rb +2 -0
  91. data/lib/mongo/version.rb +1 -1
  92. data/lib/mongo/write_concern.rb +21 -6
  93. data/mongo.gemspec +1 -2
  94. data/spec/mongo/bulk_write/ordered_combiner_spec.rb +13 -0
  95. data/spec/mongo/bulk_write_spec.rb +58 -0
  96. data/spec/mongo/client_spec.rb +6 -4
  97. data/spec/mongo/collection/view/builder/find_command_spec.rb +167 -0
  98. data/spec/mongo/collection/view/builder/flags_spec.rb +106 -0
  99. data/spec/mongo/collection/view/builder/modifiers_spec.rb +210 -0
  100. data/spec/mongo/collection/view/builder/op_query_spec.rb +154 -0
  101. data/spec/mongo/collection/view/explainable_spec.rb +1 -2
  102. data/spec/mongo/collection/view/immutable_spec.rb +3 -52
  103. data/spec/mongo/collection/view/map_reduce_spec.rb +12 -12
  104. data/spec/mongo/collection/view/readable_spec.rb +86 -80
  105. data/spec/mongo/collection/view_spec.rb +109 -703
  106. data/spec/mongo/collection_spec.rb +594 -11
  107. data/spec/mongo/command_monitoring_spec.rb +40 -27
  108. data/spec/mongo/cursor/builder/get_more_command_spec.rb +160 -0
  109. data/spec/mongo/cursor/builder/op_get_more_spec.rb +52 -0
  110. data/spec/mongo/cursor_spec.rb +10 -60
  111. data/spec/mongo/database_spec.rb +24 -3
  112. data/spec/mongo/dbref_spec.rb +4 -4
  113. data/spec/mongo/grid/file/chunk_spec.rb +1 -1
  114. data/spec/mongo/grid/fs_bucket_spec.rb +3 -3
  115. data/spec/mongo/index/view_spec.rb +41 -0
  116. data/spec/mongo/operation/{aggregate → commands/aggregate}/result_spec.rb +1 -1
  117. data/spec/mongo/operation/commands/aggregate_spec.rb +1 -1
  118. data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
  119. data/spec/mongo/operation/commands/command_spec.rb +1 -1
  120. data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
  121. data/spec/mongo/operation/commands/map_reduce_spec.rb +1 -1
  122. data/spec/mongo/operation/write/command/delete_spec.rb +25 -0
  123. data/spec/mongo/operation/write/command/insert_spec.rb +25 -0
  124. data/spec/mongo/operation/write/command/update_spec.rb +25 -0
  125. data/spec/mongo/protocol/delete_spec.rb +4 -4
  126. data/spec/mongo/protocol/get_more_spec.rb +4 -4
  127. data/spec/mongo/protocol/insert_spec.rb +3 -3
  128. data/spec/mongo/protocol/kill_cursors_spec.rb +3 -3
  129. data/spec/mongo/protocol/query_spec.rb +7 -7
  130. data/spec/mongo/protocol/update_spec.rb +5 -5
  131. data/spec/mongo/server/description/features_spec.rb +25 -0
  132. data/spec/mongo/write_concern_spec.rb +126 -0
  133. data/spec/spec_helper.rb +9 -19
  134. data/spec/support/command_monitoring.rb +8 -0
  135. data/spec/support/command_monitoring/find.yml +53 -4
  136. data/spec/support/matchers.rb +1 -1
  137. data/spec/support/shared/protocol.rb +5 -5
  138. data/spec/support/travis.rb +1 -1
  139. metadata +43 -10
  140. metadata.gz.sig +0 -0
@@ -31,10 +31,13 @@ module Mongo
31
31
  #
32
32
  # @since 2.0.0
33
33
  def find_one_and_delete
34
- cmd = { :findandmodify => collection.name, :query => selector, :remove => true }
34
+ cmd = { :findandmodify => collection.name, :query => filter, :remove => true }
35
35
  cmd[:fields] = projection if projection
36
36
  cmd[:sort] = sort if sort
37
37
  cmd[:maxTimeMS] = max_time_ms if max_time_ms
38
+ wc = options[:write_concern] || (collection.write_concern &&
39
+ collection.write_concern.options)
40
+ cmd[:writeConcern] = wc if wc
38
41
  write_with_retry do
39
42
  database.command(cmd).first['value']
40
43
  end
@@ -52,8 +55,11 @@ module Mongo
52
55
  # @param [ Hash ] opts The options.
53
56
  #
54
57
  # @option opts [ Symbol ] :return_document Either :before or :after.
55
- # @option opts [ true, false ] :upsert Whether to upsert if the
56
- # document doesn't exist.
58
+ # @option opts [ true, false ] :upsert Whether to upsert if the document doesn't exist.
59
+ # @option opts [ true, false ] :bypass_document_validation Whether or
60
+ # not to skip document level validation.
61
+ # @option options [ Hash ] :write_concern The write concern options.
62
+ # Defaults to the collection's write concern.
57
63
  #
58
64
  # @return [ BSON::Document ] The document.
59
65
  #
@@ -71,18 +77,27 @@ module Mongo
71
77
  # @param [ Hash ] opts The options.
72
78
  #
73
79
  # @option opts [ Symbol ] :return_document Either :before or :after.
80
+ # @option opts [ true, false ] :upsert Whether to upsert if the document doesn't exist.
81
+ # @option opts [ true, false ] :bypass_document_validation Whether or
82
+ # not to skip document level validation.
83
+ # @option options [ Hash ] :write_concern The write concern options.
84
+ # Defaults to the collection's write concern.
74
85
  #
75
86
  # @return [ BSON::Document ] The document.
76
87
  #
77
88
  # @since 2.0.0
78
89
  def find_one_and_update(document, opts = {})
79
- cmd = { :findandmodify => collection.name, :query => selector }
90
+ cmd = { :findandmodify => collection.name, :query => filter }
80
91
  cmd[:update] = document
81
92
  cmd[:fields] = projection if projection
82
93
  cmd[:sort] = sort if sort
83
94
  cmd[:new] = !!(opts[:return_document] && opts[:return_document] == :after)
84
95
  cmd[:upsert] = opts[:upsert] if opts[:upsert]
85
96
  cmd[:maxTimeMS] = max_time_ms if max_time_ms
97
+ cmd[:bypassDocumentValidation] = !!opts[:bypass_document_validation]
98
+ wc = options[:write_concern] || (collection.write_concern &&
99
+ collection.write_concern.options)
100
+ cmd[:writeConcern] = wc if wc
86
101
  write_with_retry do
87
102
  value = database.command(cmd).first['value']
88
103
  value unless value.nil? || value.empty?
@@ -172,7 +187,7 @@ module Mongo
172
187
  def remove(value)
173
188
  write_with_retry do
174
189
  Operation::Write::Delete.new(
175
- :delete => { Operation::Q => selector, Operation::LIMIT => value },
190
+ :delete => { Operation::Q => filter, Operation::LIMIT => value },
176
191
  :db_name => collection.database.name,
177
192
  :coll_name => collection.name,
178
193
  :write_concern => collection.write_concern
@@ -183,13 +198,14 @@ module Mongo
183
198
  def update(spec, multi, opts)
184
199
  write_with_retry do
185
200
  Operation::Write::Update.new(
186
- :update => { Operation::Q => selector,
201
+ :update => { Operation::Q => filter,
187
202
  Operation::U => spec,
188
203
  Operation::MULTI => multi,
189
204
  Operation::UPSERT => !!opts[:upsert] },
190
205
  :db_name => collection.database.name,
191
206
  :coll_name => collection.name,
192
- :write_concern => collection.write_concern
207
+ :write_concern => collection.write_concern,
208
+ :bypass_document_validation => !!opts[:bypass_document_validation]
193
209
  ).execute(next_primary.context)
194
210
  end
195
211
  end
@@ -12,6 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ require 'mongo/cursor/builder'
16
+
15
17
  module Mongo
16
18
 
17
19
  # Client-side representation of an iterator over a query result set on
@@ -35,6 +37,9 @@ module Mongo
35
37
  def_delegators :@view, :collection, :limit
36
38
  def_delegators :collection, :client, :database
37
39
 
40
+ # @return [ Collection::View ] view The collection view.
41
+ attr_reader :view
42
+
38
43
  # Creates a +Cursor+ object.
39
44
  #
40
45
  # @example Instantiate the cursor.
@@ -82,12 +87,71 @@ module Mongo
82
87
  end
83
88
  end
84
89
 
85
- private
86
-
90
+ # Get the batch size.
91
+ #
92
+ # @example Get the batch size.
93
+ # cursor.batch_size
94
+ #
95
+ # @return [ Integer ] The batch size.
96
+ #
97
+ # @since 2.2.0
87
98
  def batch_size
88
99
  @view.batch_size && @view.batch_size > 0 ? @view.batch_size : limit
89
100
  end
90
101
 
102
+ # Is the cursor closed?
103
+ #
104
+ # @example Is the cursor closed?
105
+ # cursor.closed?
106
+ #
107
+ # @return [ true, false ] If the cursor is closed.
108
+ #
109
+ # @since 2.2.0
110
+ def closed?
111
+ !more?
112
+ end
113
+
114
+ # Get the parsed collection name.
115
+ #
116
+ # @example Get the parsed collection name.
117
+ # cursor.coll_name
118
+ #
119
+ # @return [ String ] The collection name.
120
+ #
121
+ # @since 2.2.0
122
+ def collection_name
123
+ @coll_name || collection.name
124
+ end
125
+
126
+ # Get the cursor id.
127
+ #
128
+ # @example Get the cursor id.
129
+ # cursor.id
130
+ #
131
+ # @note A cursor id of 0 means the cursor was closed on the server.
132
+ #
133
+ # @return [ Integer ] The cursor id.
134
+ #
135
+ # @since 2.2.0
136
+ def id
137
+ @cursor_id
138
+ end
139
+
140
+ # Get the number of documents to return. Used on 3.0 and lower server
141
+ # versions.
142
+ #
143
+ # @example Get the number to return.
144
+ # cursor.to_return
145
+ #
146
+ # @return [ Integer ] The number of documents to return.
147
+ #
148
+ # @since 2.2.0
149
+ def to_return
150
+ use_limit? ? @remaining : (batch_size || 0)
151
+ end
152
+
153
+ private
154
+
91
155
  def exhausted?
92
156
  limited? ? @remaining <= 0 : false
93
157
  end
@@ -97,16 +161,11 @@ module Mongo
97
161
  end
98
162
 
99
163
  def get_more_operation
100
- Operation::Read::GetMore.new(get_more_spec)
101
- end
102
-
103
- def get_more_spec
104
- {
105
- :to_return => to_return,
106
- :cursor_id => @cursor_id,
107
- :db_name => database.name,
108
- :coll_name => @coll_name || collection.name
109
- }
164
+ if @server.features.find_command_enabled?
165
+ Operation::Commands::GetMore.new(Builder::GetMoreCommand.new(self).specification)
166
+ else
167
+ Operation::Read::GetMore.new(Builder::OpGetMore.new(self).specification)
168
+ end
110
169
  end
111
170
 
112
171
  def kill_cursors
@@ -114,15 +173,11 @@ module Mongo
114
173
  end
115
174
 
116
175
  def kill_cursors_operation
117
- Operation::KillCursors.new(kill_cursors_spec)
118
- end
119
-
120
- def kill_cursors_spec
121
- {
122
- :coll_name => @coll_name || collection.name,
123
- :db_name => database.name,
124
- :cursor_ids => [ @cursor_id ]
125
- }
176
+ if @server.features.find_command_enabled?
177
+ Operation::Commands::Command.new(Builder::KillCursorsCommand.new(self).specification)
178
+ else
179
+ Operation::KillCursors.new(Builder::OpKillCursors.new(self).specification)
180
+ end
126
181
  end
127
182
 
128
183
  def limited?
@@ -140,10 +195,6 @@ module Mongo
140
195
  result.documents
141
196
  end
142
197
 
143
- def to_return
144
- use_limit? ? @remaining : (batch_size || 0)
145
- end
146
-
147
198
  def use_limit?
148
199
  limited? && batch_size >= @remaining
149
200
  end
@@ -0,0 +1,18 @@
1
+ # Copyright (C) 2015 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'mongo/cursor/builder/op_get_more'
16
+ require 'mongo/cursor/builder/op_kill_cursors'
17
+ require 'mongo/cursor/builder/get_more_command'
18
+ require 'mongo/cursor/builder/kill_cursors_command'
@@ -0,0 +1,71 @@
1
+ # Copyright (C) 2015 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Mongo
16
+ class Cursor
17
+ module Builder
18
+
19
+ # Generates a specification for a get more command.
20
+ #
21
+ # @since 2.2.0
22
+ class GetMoreCommand
23
+ extend Forwardable
24
+
25
+ # @return [ Cursor ] cursor The cursor.
26
+ attr_reader :cursor
27
+
28
+ def_delegators :@cursor, :batch_size, :collection_name, :database, :view
29
+
30
+ # Create the new builder.
31
+ #
32
+ # @example Create the builder.
33
+ # GetMoreCommand.new(cursor)
34
+ #
35
+ # @param [ Cursor ] cursor The cursor.
36
+ #
37
+ # @since 2.2.0
38
+ def initialize(cursor)
39
+ @cursor = cursor
40
+ end
41
+
42
+ # Get the specification.
43
+ #
44
+ # @example Get the specification.
45
+ # get_more_command.specification
46
+ #
47
+ # @return [ Hash ] The spec.
48
+ #
49
+ # @since 2.2.0
50
+ def specification
51
+ { selector: get_more_command, db_name: database.name }
52
+ end
53
+
54
+ private
55
+
56
+ def get_more_command
57
+ command = { :getMore => cursor.id, :collection => collection_name }
58
+ command[:batchSize] = batch_size if batch_size
59
+ # If the max_await_time_ms option is set, then we set maxTimeMS on
60
+ # the get more command.
61
+ if view.respond_to?(:max_await_time_ms)
62
+ if view.max_await_time_ms && view.options[:await_data]
63
+ command[:maxTimeMS] = view.max_await_time_ms
64
+ end
65
+ end
66
+ command
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright (C) 2015 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Mongo
16
+ class Cursor
17
+ module Builder
18
+
19
+ # Generates a specification for a kill cursors command.
20
+ #
21
+ # @since 2.2.0
22
+ class KillCursorsCommand
23
+ extend Forwardable
24
+
25
+ # @return [ Cursor ] cursor The cursor.
26
+ attr_reader :cursor
27
+
28
+ def_delegators :@cursor, :collection_name, :database
29
+
30
+ # Create the new builder.
31
+ #
32
+ # @example Create the builder.
33
+ # KillCursorsCommand.new(cursor)
34
+ #
35
+ # @param [ Cursor ] cursor The cursor.
36
+ #
37
+ # @since 2.2.0
38
+ def initialize(cursor)
39
+ @cursor = cursor
40
+ end
41
+
42
+ # Get the specification.
43
+ #
44
+ # @example Get the specification.
45
+ # kill_cursors_command.specification
46
+ #
47
+ # @return [ Hash ] The spec.
48
+ #
49
+ # @since 2.2.0
50
+ def specification
51
+ { selector: kill_cursors_command, db_name: database.name }
52
+ end
53
+
54
+ private
55
+
56
+ def kill_cursors_command
57
+ { :killCursors => collection_name, :cursors => [ cursor.id ] }
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,61 @@
1
+ # Copyright (C) 2015 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Mongo
16
+ class Cursor
17
+ module Builder
18
+
19
+ # Encapsulates behaviour around generating an OP_GET_MORE specification.
20
+ #
21
+ # @since 2.2.0
22
+ class OpGetMore
23
+ extend Forwardable
24
+
25
+ # @return [ Cursor ] cursor The cursor.
26
+ attr_reader :cursor
27
+
28
+ def_delegators :@cursor, :collection_name, :database, :to_return
29
+
30
+ # Create the new builder.
31
+ #
32
+ # @example Create the builder.
33
+ # OpGetMore.new(cursor)
34
+ #
35
+ # @param [ Cursor ] cursor The cursor.
36
+ #
37
+ # @since 2.2.0
38
+ def initialize(cursor)
39
+ @cursor = cursor
40
+ end
41
+
42
+ # Get the specification.
43
+ #
44
+ # @example Get the specification.
45
+ # op_get_more.specification
46
+ #
47
+ # @return [ Hash ] The specification.
48
+ #
49
+ # @since 2.2.0
50
+ def specification
51
+ {
52
+ :to_return => to_return,
53
+ :cursor_id => cursor.id,
54
+ :db_name => database.name,
55
+ :coll_name => collection_name
56
+ }
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,56 @@
1
+ # Copyright (C) 2015 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Mongo
16
+ class Cursor
17
+ module Builder
18
+
19
+ # Encapsulates behaviour around generating an OP_KILL_CURSORS specification.
20
+ #
21
+ # @since 2.2.0
22
+ class OpKillCursors
23
+ extend Forwardable
24
+
25
+ # @return [ Cursor ] cursor The cursor.
26
+ attr_reader :cursor
27
+
28
+ def_delegators :@cursor, :collection_name, :database
29
+
30
+ # Create the new builder.
31
+ #
32
+ # @example Create the builder.
33
+ # OpKillCursors.new(cursor)
34
+ #
35
+ # @param [ Cursor ] cursor The cursor.
36
+ #
37
+ # @since 2.2.0
38
+ def initialize(cursor)
39
+ @cursor = cursor
40
+ end
41
+
42
+ # Get the specification.
43
+ #
44
+ # @example Get the specification.
45
+ # op_kill_cursors.specification
46
+ #
47
+ # @return [ Hash ] The specification.
48
+ #
49
+ # @since 2.2.0
50
+ def specification
51
+ { :coll_name => collection_name, :db_name => database.name, :cursor_ids => [ cursor.id ] }
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end